Revert "Revert "further fixes for void stripping. fixes tvoid.""
This reverts commit d11cf5d191.
This commit is contained in:
parent
cefa16ae77
commit
a453d8d64d
1 changed files with 25 additions and 20 deletions
|
|
@ -148,7 +148,7 @@ proc instGenericContainer(c: PContext, info: TLineInfo, header: PType): PType =
|
||||||
proc instGenericContainer(c: PContext, n: PNode, header: PType): PType =
|
proc instGenericContainer(c: PContext, n: PNode, header: PType): PType =
|
||||||
result = instGenericContainer(c, n.info, header)
|
result = instGenericContainer(c, n.info, header)
|
||||||
|
|
||||||
proc fixupProcTypeR(c: PContext, genericType: PType,
|
proc fixupProcType(c: PContext, genericType: PType,
|
||||||
inst: TInstantiation): PType =
|
inst: TInstantiation): PType =
|
||||||
result = genericType
|
result = genericType
|
||||||
if result == nil: return
|
if result == nil: return
|
||||||
|
|
@ -167,48 +167,53 @@ proc fixupProcTypeR(c: PContext, genericType: PType,
|
||||||
if genericType.sons == nil: return
|
if genericType.sons == nil: return
|
||||||
var head = 0
|
var head = 0
|
||||||
for i in 0 .. <genericType.sons.len:
|
for i in 0 .. <genericType.sons.len:
|
||||||
let changed = fixupProcTypeR(c, genericType.sons[i], inst)
|
var changed = fixupProcType(c, genericType.sons[i], inst)
|
||||||
if changed != genericType.sons[i]:
|
if changed != genericType.sons[i]:
|
||||||
|
var changed = changed.skipIntLit
|
||||||
if result == genericType:
|
if result == genericType:
|
||||||
# the first detected change initializes the result
|
# the first detected change initializes the result
|
||||||
result = copyType(genericType, genericType.owner, false)
|
result = copyType(genericType, genericType.owner, false)
|
||||||
if genericType.n != nil:
|
if genericType.n != nil:
|
||||||
result.n = copyTree(genericType.n)
|
result.n = copyTree(genericType.n)
|
||||||
if changed.kind == tyEmpty:
|
|
||||||
|
# XXX: doh, we have to treat seq and arrays as special case
|
||||||
|
# because sometimes the `@` magic will be applied to an empty
|
||||||
|
# sequence having the type tySequence(tyEmpty)
|
||||||
|
if changed.kind == tyEmpty and
|
||||||
|
genericType.kind notin {tyArray, tySequence}:
|
||||||
|
if genericType.kind == tyProc and i == 0:
|
||||||
|
# return types of procs are overwritten with nil
|
||||||
|
changed = nil
|
||||||
|
else:
|
||||||
|
# otherwise, `empty` is just erased from the signature
|
||||||
result.sons[i..i] = []
|
result.sons[i..i] = []
|
||||||
if result.n != nil: result.n.sons[i..i] = []
|
if result.n != nil: result.n.sons[i..i] = []
|
||||||
continue
|
continue
|
||||||
let changed = changed.skipIntLit
|
|
||||||
result.sons[head] = changed
|
result.sons[head] = changed
|
||||||
|
|
||||||
if result.n != nil:
|
if result.n != nil:
|
||||||
if result.n.kind == nkRecList:
|
if result.n.kind == nkRecList:
|
||||||
result.n.sons[head].typ = changed
|
result.n.sons[head].typ = changed
|
||||||
if result.n.kind == nkFormalParams:
|
if result.n.kind == nkFormalParams:
|
||||||
if i == 0:
|
if i != 0:
|
||||||
nil
|
|
||||||
else:
|
|
||||||
let origParam = result.n.sons[head].sym
|
let origParam = result.n.sons[head].sym
|
||||||
var param = copySym(origParam)
|
var param = copySym(origParam)
|
||||||
param.typ = changed
|
param.typ = changed
|
||||||
param.ast = origParam.ast
|
param.ast = origParam.ast
|
||||||
result.n.sons[head] = newSymNode(param)
|
result.n.sons[head] = newSymNode(param)
|
||||||
|
|
||||||
|
# won't be advanced on empty (void) nodes
|
||||||
inc head
|
inc head
|
||||||
|
|
||||||
of tyGenericInvokation:
|
of tyGenericInvokation:
|
||||||
result = newTypeWithSons(c, tyGenericInvokation, genericType.sons)
|
result = newTypeWithSons(c, tyGenericInvokation, genericType.sons)
|
||||||
for i in 1 .. <genericType.sons.len:
|
for i in 1 .. <genericType.sons.len:
|
||||||
result.sons[i] = fixupProcTypeR(c, result.sons[i], inst)
|
result.sons[i] = fixupProcType(c, result.sons[i], inst)
|
||||||
result = instGenericContainer(c, getInfoContext(-1), result)
|
result = instGenericContainer(c, getInfoContext(-1), result)
|
||||||
else:
|
else:
|
||||||
nil
|
nil
|
||||||
|
|
||||||
proc fixupProcType(c: PContext, genericType: PType,
|
|
||||||
inst: TInstantiation): PType =
|
|
||||||
result = copyType(genericType, genericType.owner, false)
|
|
||||||
result = fixupProcTypeR(c, result, inst)
|
|
||||||
for i in 0 .. <result.sons.len:
|
|
||||||
result.sons[i] = fixupProcTypeR(c, result.sons[i], inst)
|
|
||||||
|
|
||||||
proc generateInstance(c: PContext, fn: PSym, pt: TIdTable,
|
proc generateInstance(c: PContext, fn: PSym, pt: TIdTable,
|
||||||
info: TLineInfo): PSym =
|
info: TLineInfo): PSym =
|
||||||
# no need to instantiate generic templates/macros:
|
# no need to instantiate generic templates/macros:
|
||||||
|
|
@ -238,7 +243,7 @@ proc generateInstance(c: PContext, fn: PSym, pt: TIdTable,
|
||||||
var entry = TInstantiation.new
|
var entry = TInstantiation.new
|
||||||
entry.sym = result
|
entry.sym = result
|
||||||
instantiateGenericParamList(c, n.sons[genericParamsPos], pt, entry[])
|
instantiateGenericParamList(c, n.sons[genericParamsPos], pt, entry[])
|
||||||
result.typ = fixupProcTypeR(c, fn.typ, entry[])
|
result.typ = fixupProcType(c, fn.typ, entry[])
|
||||||
n.sons[genericParamsPos] = ast.emptyNode
|
n.sons[genericParamsPos] = ast.emptyNode
|
||||||
var oldPrc = GenericCacheGet(fn, entry[])
|
var oldPrc = GenericCacheGet(fn, entry[])
|
||||||
if oldPrc == nil:
|
if oldPrc == nil:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue