fixes #211
transf: fix a clang compilation error when lineDir:on is used
This commit is contained in:
parent
6e4c23bd32
commit
4ef96a7435
5 changed files with 25 additions and 9 deletions
|
|
@ -287,6 +287,11 @@ type
|
||||||
tyGenericInvokation, # ``T[a, b]`` for types to invoke
|
tyGenericInvokation, # ``T[a, b]`` for types to invoke
|
||||||
tyGenericBody, # ``T[a, b, body]`` last parameter is the body
|
tyGenericBody, # ``T[a, b, body]`` last parameter is the body
|
||||||
tyGenericInst, # ``T[a, b, realInstance]`` instantiated generic type
|
tyGenericInst, # ``T[a, b, realInstance]`` instantiated generic type
|
||||||
|
# realInstance will be a concrete type like tyObject
|
||||||
|
# unless this is an instance of a generic alias type.
|
||||||
|
# then realInstance will be the tyGenericInst of the
|
||||||
|
# completely (recursively) resolved alias.
|
||||||
|
|
||||||
tyGenericParam, # ``a`` in the above patterns
|
tyGenericParam, # ``a`` in the above patterns
|
||||||
tyDistinct,
|
tyDistinct,
|
||||||
tyEnum,
|
tyEnum,
|
||||||
|
|
|
||||||
|
|
@ -171,6 +171,10 @@ proc handleGenericInvokation(cl: var TReplTypeVars, t: PType): PType =
|
||||||
result.flags = result.flags + newbody.flags
|
result.flags = result.flags + newbody.flags
|
||||||
newbody.callConv = body.callConv
|
newbody.callConv = body.callConv
|
||||||
newbody.n = ReplaceTypeVarsN(cl, lastSon(body).n)
|
newbody.n = ReplaceTypeVarsN(cl, lastSon(body).n)
|
||||||
|
# This type may be a generic alias and we want to resolve it here.
|
||||||
|
# One step is enough, because the recursive nature of
|
||||||
|
# handleGenericInvokation will handle the alias-to-alias-to-alias case
|
||||||
|
if newbody.isGenericAlias: newbody = newbody.skipGenericAlias
|
||||||
rawAddSon(result, newbody)
|
rawAddSon(result, newbody)
|
||||||
checkPartialConstructedType(cl.info, newbody)
|
checkPartialConstructedType(cl.info, newbody)
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -476,22 +476,23 @@ proc typeRel(c: var TCandidate, f, a: PType): TTypeRelation =
|
||||||
let ff = lastSon(f)
|
let ff = lastSon(f)
|
||||||
if ff != nil: result = typeRel(c, ff, a)
|
if ff != nil: result = typeRel(c, ff, a)
|
||||||
of tyGenericInvokation:
|
of tyGenericInvokation:
|
||||||
|
var x = a.skipGenericAlias
|
||||||
assert(f.sons[0].kind == tyGenericBody)
|
assert(f.sons[0].kind == tyGenericBody)
|
||||||
if a.kind == tyGenericInvokation:
|
if x.kind == tyGenericInvokation:
|
||||||
#InternalError("typeRel: tyGenericInvokation -> tyGenericInvokation")
|
#InternalError("typeRel: tyGenericInvokation -> tyGenericInvokation")
|
||||||
# simply no match for now:
|
# simply no match for now:
|
||||||
nil
|
nil
|
||||||
elif a.kind == tyGenericInst and
|
elif x.kind == tyGenericInst and
|
||||||
(f.sons[0].containerID == a.sons[0].containerID) and
|
(f.sons[0].containerID == x.sons[0].containerID) and
|
||||||
(sonsLen(a) - 1 == sonsLen(f)):
|
(sonsLen(x) - 1 == sonsLen(f)):
|
||||||
assert(a.sons[0].kind == tyGenericBody)
|
assert(x.sons[0].kind == tyGenericBody)
|
||||||
for i in countup(1, sonsLen(f) - 1):
|
for i in countup(1, sonsLen(f) - 1):
|
||||||
if a.sons[i].kind == tyGenericParam:
|
if x.sons[i].kind == tyGenericParam:
|
||||||
InternalError("wrong instantiated type!")
|
InternalError("wrong instantiated type!")
|
||||||
elif typeRel(c, f.sons[i], a.sons[i]) <= isSubtype: return
|
elif typeRel(c, f.sons[i], x.sons[i]) <= isSubtype: return
|
||||||
result = isGeneric
|
result = isGeneric
|
||||||
else:
|
else:
|
||||||
result = typeRel(c, f.sons[0], a)
|
result = typeRel(c, f.sons[0], x)
|
||||||
if result != isNone:
|
if result != isNone:
|
||||||
# we steal the generic parameters from the tyGenericBody:
|
# we steal the generic parameters from the tyGenericBody:
|
||||||
for i in countup(1, sonsLen(f) - 1):
|
for i in countup(1, sonsLen(f) - 1):
|
||||||
|
|
|
||||||
|
|
@ -603,7 +603,7 @@ proc transform(c: PTransf, n: PNode): PTransNode =
|
||||||
dec c.inLoop
|
dec c.inLoop
|
||||||
of nkCaseStmt: result = transformCase(c, n)
|
of nkCaseStmt: result = transformCase(c, n)
|
||||||
of nkContinueStmt:
|
of nkContinueStmt:
|
||||||
result = PTransNode(newNode(nkBreakStmt))
|
result = PTransNode(newNodeI(nkBreakStmt, n.info))
|
||||||
var labl = c.contSyms[c.contSyms.high]
|
var labl = c.contSyms[c.contSyms.high]
|
||||||
add(result, PTransNode(newSymNode(labl)))
|
add(result, PTransNode(newSymNode(labl)))
|
||||||
of nkBreakStmt: result = transformBreak(c, n)
|
of nkBreakStmt: result = transformBreak(c, n)
|
||||||
|
|
|
||||||
|
|
@ -905,6 +905,12 @@ proc matchType*(a: PType, pattern: openArray[tuple[k:TTypeKind, i:int]],
|
||||||
a = a.sons[i]
|
a = a.sons[i]
|
||||||
result = a.kind == last
|
result = a.kind == last
|
||||||
|
|
||||||
|
proc isGenericAlias*(t: PType): bool =
|
||||||
|
return t.kind == tyGenericInst and t.lastSon.kind == tyGenericInst
|
||||||
|
|
||||||
|
proc skipGenericAlias*(t: PType): PType =
|
||||||
|
return if t.isGenericAlias: t.lastSon else: t
|
||||||
|
|
||||||
proc matchTypeClass*(bindings: var TIdTable, typeClass, t: PType): bool =
|
proc matchTypeClass*(bindings: var TIdTable, typeClass, t: PType): bool =
|
||||||
for i in countup(0, typeClass.sonsLen - 1):
|
for i in countup(0, typeClass.sonsLen - 1):
|
||||||
let req = typeClass.sons[i]
|
let req = typeClass.sons[i]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue