macros.getType: do not copy symbols if not necessary

This commit is contained in:
Araq 2016-12-07 20:08:03 +01:00
commit dc5e4b018b

View file

@ -73,6 +73,10 @@ proc atomicTypeX(name: string; m: TMagic; t: PType; info: TLineInfo): PNode =
result = newSymNode(sym) result = newSymNode(sym)
result.typ = t result.typ = t
proc atomicTypeX(s: PSym; info: TLineInfo): PNode =
result = newSymNode(s)
result.info = info
proc mapTypeToAstX(t: PType; info: TLineInfo; proc mapTypeToAstX(t: PType; info: TLineInfo;
inst=false; allowRecursionX=false): PNode inst=false; allowRecursionX=false): PNode
@ -103,6 +107,7 @@ proc mapTypeToAstX(t: PType; info: TLineInfo;
inst=false; allowRecursionX=false): PNode = inst=false; allowRecursionX=false): PNode =
var allowRecursion = allowRecursionX var allowRecursion = allowRecursionX
template atomicType(name, m): untyped = atomicTypeX(name, m, t, info) template atomicType(name, m): untyped = atomicTypeX(name, m, t, info)
template atomicType(s): untyped = atomicTypeX(s, info)
template mapTypeToAst(t,info): untyped = mapTypeToAstX(t, info, inst) template mapTypeToAst(t,info): untyped = mapTypeToAstX(t, info, inst)
template mapTypeToAstR(t,info): untyped = mapTypeToAstX(t, info, inst, true) template mapTypeToAstR(t,info): untyped = mapTypeToAstX(t, info, inst, true)
template mapTypeToAst(t,i,info): untyped = template mapTypeToAst(t,i,info): untyped =
@ -125,7 +130,7 @@ proc mapTypeToAstX(t: PType; info: TLineInfo;
if allowRecursion: # getTypeImpl behavior: turn off recursion if allowRecursion: # getTypeImpl behavior: turn off recursion
allowRecursion = false allowRecursion = false
else: # getTypeInst behavior: return symbol else: # getTypeInst behavior: return symbol
return atomicType(t.sym.name.s, t.sym.magic) return atomicType(t.sym)
case t.kind case t.kind
of tyNone: result = atomicType("none", mNone) of tyNone: result = atomicType("none", mNone)
@ -180,9 +185,9 @@ proc mapTypeToAstX(t: PType; info: TLineInfo;
if allowRecursion or t.sym == nil: if allowRecursion or t.sym == nil:
result = mapTypeToBracket("distinct", mDistinct, t, info) result = mapTypeToBracket("distinct", mDistinct, t, info)
else: else:
result = atomicType(t.sym.name.s, t.sym.magic) result = atomicType(t.sym)
of tyGenericParam, tyForward: of tyGenericParam, tyForward:
result = atomicType(t.sym.name.s, t.sym.magic) result = atomicType(t.sym)
of tyObject: of tyObject:
if inst: if inst:
result = newNodeX(nkObjectTy) result = newNodeX(nkObjectTy)
@ -206,7 +211,7 @@ proc mapTypeToAstX(t: PType; info: TLineInfo;
result.add mapTypeToAst(t.sons[0], info) result.add mapTypeToAst(t.sons[0], info)
result.add copyTree(t.n) result.add copyTree(t.n)
else: else:
result = atomicType(t.sym.name.s, t.sym.magic) result = atomicType(t.sym)
of tyEnum: of tyEnum:
result = newNodeIT(nkEnumTy, if t.n.isNil: info else: t.n.info, t) result = newNodeIT(nkEnumTy, if t.n.isNil: info else: t.n.info, t)
result.add copyTree(t.n) result.add copyTree(t.n)