mirror of
https://github.com/nim-lang/Nim.git
synced 2026-07-18 23:11:36 +00:00
added missing type flags
This commit is contained in:
@@ -347,7 +347,7 @@ type
|
||||
nfSem # node has been checked for semantics
|
||||
|
||||
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
|
||||
tfNoSideEffect, # procedure type does not allow side effects
|
||||
tfFinal, # is the object final?
|
||||
@@ -359,19 +359,22 @@ type
|
||||
tfFromGeneric, # type is an instantiation of a generic; this is needed
|
||||
# because for instantiations of objects, structural
|
||||
# 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
|
||||
# this can lead to invalid proc signatures in the second
|
||||
# pass of semProcTypeNode performed after instantiation.
|
||||
# this won't be needed if we don't perform this redundant
|
||||
# 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)
|
||||
tfAll, # type class requires all constraints to be met (default)
|
||||
tfAny, # type class requires any constraint to be met
|
||||
tfCapturesEnv, # whether proc really captures some environment
|
||||
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]
|
||||
|
||||
@@ -412,6 +415,9 @@ const
|
||||
skMacro, skTemplate}
|
||||
tfIncompleteStruct* = tfVarargs
|
||||
skError* = skUnknown
|
||||
|
||||
# type flags that are essential for type equality:
|
||||
eqTypeFlags* = {tfIterator, tfShared, tfNotNil}
|
||||
|
||||
type
|
||||
TMagic* = enum # symbols that require compiler magic:
|
||||
|
||||
@@ -882,7 +882,7 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
|
||||
of nkPtrTy: result = semAnyRef(c, n, tyPtr, prev)
|
||||
of nkVarTy: result = semVarType(c, n, prev)
|
||||
of nkDistinctTy: result = semDistinct(c, n, prev)
|
||||
of nkProcTy:
|
||||
of nkProcTy, nkIteratorTy:
|
||||
if n.sonsLen == 0: return newConstraint(c, tyProc)
|
||||
checkSonsLen(n, 2)
|
||||
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)
|
||||
else:
|
||||
result = t.id == startId
|
||||
if t.kind == tyObject and tfFinal notin t.flags:
|
||||
# damn inheritance may introduce cycles:
|
||||
result = true
|
||||
# Inheritance can introduce cyclic types, however this is not relevant
|
||||
# as the type that is passed to 'new' is statically known!
|
||||
#if t.kind == tyObject and tfFinal notin t.flags:
|
||||
# # damn inheritance may introduce cycles:
|
||||
# result = true
|
||||
else: nil
|
||||
|
||||
proc canFormAcycle(typ: PType): bool =
|
||||
@@ -410,7 +412,7 @@ proc TypeToString(typ: PType, prefer: TPreferedDesc = preferName): string =
|
||||
"float", "float32", "float64", "float128",
|
||||
"uint", "uint8", "uint16", "uint32", "uint64",
|
||||
"bignum", "const ",
|
||||
"!", "varargs[$1]", "iter[$1]", "Error Type", "TypeClass" ]
|
||||
"!", "varargs[$1]", "iter[$1]", "Error Type", "TypeClass"]
|
||||
var t = typ
|
||||
result = ""
|
||||
if t == nil: return
|
||||
@@ -476,8 +478,8 @@ proc TypeToString(typ: PType, prefer: TPreferedDesc = preferName): string =
|
||||
result = typeToStr[t.kind] & typeToString(t.sons[0])
|
||||
of tyRange:
|
||||
result = "range " & rangeToStr(t.n)
|
||||
of tyProc:
|
||||
result = "proc ("
|
||||
of tyProc:
|
||||
result = if tfIterator in t.flags: "iterator (" else: "proc ("
|
||||
for i in countup(1, sonsLen(t) - 1):
|
||||
add(result, typeToString(t.sons[i]))
|
||||
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])
|
||||
else:
|
||||
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 =
|
||||
assert(t.kind == tyProc)
|
||||
|
||||
@@ -9,12 +9,12 @@ type
|
||||
getter2: proc(): int {.closure.}]
|
||||
|
||||
proc getInterf(): ITest =
|
||||
var shared, shared2: int
|
||||
var shared1, shared2: int
|
||||
|
||||
return (setter: proc (x: int) =
|
||||
shared = x
|
||||
shared1 = x
|
||||
shared2 = x + 10,
|
||||
getter1: proc (): int = result = shared,
|
||||
getter1: proc (): int = result = shared1,
|
||||
getter2: proc (): int = return shared2)
|
||||
|
||||
var i = getInterf()
|
||||
|
||||
Reference in New Issue
Block a user