added missing type flags
This commit is contained in:
parent
4bef5a7a78
commit
019d6e4127
4 changed files with 24 additions and 14 deletions
|
|
@ -347,7 +347,7 @@ type
|
||||||
nfSem # node has been checked for semantics
|
nfSem # node has been checked for semantics
|
||||||
|
|
||||||
TNodeFlags* = set[TNodeFlag]
|
TNodeFlags* = set[TNodeFlag]
|
||||||
TTypeFlag* = enum # keep below 17 for efficiency reasons (now: 16)
|
TTypeFlag* = enum # keep below 32 for efficiency reasons (now: 19)
|
||||||
tfVarargs, # procedure has C styled varargs
|
tfVarargs, # procedure has C styled varargs
|
||||||
tfNoSideEffect, # procedure type does not allow side effects
|
tfNoSideEffect, # procedure type does not allow side effects
|
||||||
tfFinal, # is the object final?
|
tfFinal, # is the object final?
|
||||||
|
|
@ -359,19 +359,22 @@ type
|
||||||
tfFromGeneric, # type is an instantiation of a generic; this is needed
|
tfFromGeneric, # type is an instantiation of a generic; this is needed
|
||||||
# because for instantiations of objects, structural
|
# because for instantiations of objects, structural
|
||||||
# type equality has to be used
|
# type equality has to be used
|
||||||
tfInstantiated # XXX: used to mark generic params after instantiation.
|
tfInstantiated, # XXX: used to mark generic params after instantiation.
|
||||||
# if the concrete type happens to be an implicit generic
|
# if the concrete type happens to be an implicit generic
|
||||||
# this can lead to invalid proc signatures in the second
|
# this can lead to invalid proc signatures in the second
|
||||||
# pass of semProcTypeNode performed after instantiation.
|
# pass of semProcTypeNode performed after instantiation.
|
||||||
# this won't be needed if we don't perform this redundant
|
# this won't be needed if we don't perform this redundant
|
||||||
# second pass (stay tuned).
|
# second pass (stay tuned).
|
||||||
tfRetType # marks return types in proc (used to detect type classes
|
tfRetType, # marks return types in proc (used to detect type classes
|
||||||
# used as return types for return type inference)
|
# used as return types for return type inference)
|
||||||
tfAll, # type class requires all constraints to be met (default)
|
tfAll, # type class requires all constraints to be met (default)
|
||||||
tfAny, # type class requires any constraint to be met
|
tfAny, # type class requires any constraint to be met
|
||||||
tfCapturesEnv, # whether proc really captures some environment
|
tfCapturesEnv, # whether proc really captures some environment
|
||||||
tfByCopy, # pass object/tuple by copy (C backend)
|
tfByCopy, # pass object/tuple by copy (C backend)
|
||||||
tfByRef # pass object/tuple by reference (C backend)
|
tfByRef, # pass object/tuple by reference (C backend)
|
||||||
|
tfIterator, # type is really an iterator, not a tyProc
|
||||||
|
tfShared, # type is 'shared'
|
||||||
|
tfNotNil # type cannot be 'nil'
|
||||||
|
|
||||||
TTypeFlags* = set[TTypeFlag]
|
TTypeFlags* = set[TTypeFlag]
|
||||||
|
|
||||||
|
|
@ -413,6 +416,9 @@ const
|
||||||
tfIncompleteStruct* = tfVarargs
|
tfIncompleteStruct* = tfVarargs
|
||||||
skError* = skUnknown
|
skError* = skUnknown
|
||||||
|
|
||||||
|
# type flags that are essential for type equality:
|
||||||
|
eqTypeFlags* = {tfIterator, tfShared, tfNotNil}
|
||||||
|
|
||||||
type
|
type
|
||||||
TMagic* = enum # symbols that require compiler magic:
|
TMagic* = enum # symbols that require compiler magic:
|
||||||
mNone,
|
mNone,
|
||||||
|
|
|
||||||
|
|
@ -882,7 +882,7 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
|
||||||
of nkPtrTy: result = semAnyRef(c, n, tyPtr, prev)
|
of nkPtrTy: result = semAnyRef(c, n, tyPtr, prev)
|
||||||
of nkVarTy: result = semVarType(c, n, prev)
|
of nkVarTy: result = semVarType(c, n, prev)
|
||||||
of nkDistinctTy: result = semDistinct(c, n, prev)
|
of nkDistinctTy: result = semDistinct(c, n, prev)
|
||||||
of nkProcTy:
|
of nkProcTy, nkIteratorTy:
|
||||||
if n.sonsLen == 0: return newConstraint(c, tyProc)
|
if n.sonsLen == 0: return newConstraint(c, tyProc)
|
||||||
checkSonsLen(n, 2)
|
checkSonsLen(n, 2)
|
||||||
openScope(c.tab)
|
openScope(c.tab)
|
||||||
|
|
|
||||||
|
|
@ -339,9 +339,11 @@ proc canFormAcycleAux(marker: var TIntSet, typ: PType, startId: int): bool =
|
||||||
if t.n != nil: result = canFormAcycleNode(marker, t.n, startId)
|
if t.n != nil: result = canFormAcycleNode(marker, t.n, startId)
|
||||||
else:
|
else:
|
||||||
result = t.id == startId
|
result = t.id == startId
|
||||||
if t.kind == tyObject and tfFinal notin t.flags:
|
# Inheritance can introduce cyclic types, however this is not relevant
|
||||||
# damn inheritance may introduce cycles:
|
# as the type that is passed to 'new' is statically known!
|
||||||
result = true
|
#if t.kind == tyObject and tfFinal notin t.flags:
|
||||||
|
# # damn inheritance may introduce cycles:
|
||||||
|
# result = true
|
||||||
else: nil
|
else: nil
|
||||||
|
|
||||||
proc canFormAcycle(typ: PType): bool =
|
proc canFormAcycle(typ: PType): bool =
|
||||||
|
|
@ -477,7 +479,7 @@ proc TypeToString(typ: PType, prefer: TPreferedDesc = preferName): string =
|
||||||
of tyRange:
|
of tyRange:
|
||||||
result = "range " & rangeToStr(t.n)
|
result = "range " & rangeToStr(t.n)
|
||||||
of tyProc:
|
of tyProc:
|
||||||
result = "proc ("
|
result = if tfIterator in t.flags: "iterator (" else: "proc ("
|
||||||
for i in countup(1, sonsLen(t) - 1):
|
for i in countup(1, sonsLen(t) - 1):
|
||||||
add(result, typeToString(t.sons[i]))
|
add(result, typeToString(t.sons[i]))
|
||||||
if i < sonsLen(t) - 1: add(result, ", ")
|
if i < sonsLen(t) - 1: add(result, ", ")
|
||||||
|
|
@ -497,6 +499,8 @@ proc TypeToString(typ: PType, prefer: TPreferedDesc = preferName): string =
|
||||||
result = typeToStr[t.kind] % typeToString(t.sons[0])
|
result = typeToStr[t.kind] % typeToString(t.sons[0])
|
||||||
else:
|
else:
|
||||||
result = typeToStr[t.kind]
|
result = typeToStr[t.kind]
|
||||||
|
if tfShared in t.flags: result = "shared " & result
|
||||||
|
if tfNotNil in t.flags: result.add(" not nil")
|
||||||
|
|
||||||
proc resultType(t: PType): PType =
|
proc resultType(t: PType): PType =
|
||||||
assert(t.kind == tyProc)
|
assert(t.kind == tyProc)
|
||||||
|
|
|
||||||
|
|
@ -9,12 +9,12 @@ type
|
||||||
getter2: proc(): int {.closure.}]
|
getter2: proc(): int {.closure.}]
|
||||||
|
|
||||||
proc getInterf(): ITest =
|
proc getInterf(): ITest =
|
||||||
var shared, shared2: int
|
var shared1, shared2: int
|
||||||
|
|
||||||
return (setter: proc (x: int) =
|
return (setter: proc (x: int) =
|
||||||
shared = x
|
shared1 = x
|
||||||
shared2 = x + 10,
|
shared2 = x + 10,
|
||||||
getter1: proc (): int = result = shared,
|
getter1: proc (): int = result = shared1,
|
||||||
getter2: proc (): int = return shared2)
|
getter2: proc (): int = return shared2)
|
||||||
|
|
||||||
var i = getInterf()
|
var i = getInterf()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue