diff options
author | Araq <rumpf_a@web.de> | 2012-11-23 19:52:32 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2012-11-23 19:52:32 +0100 |
commit | 019d6e4127a1dbe7ba8be4cc40c3c9358b1c48b3 (patch) | |
tree | 5db59c762fddd1048e8be437fec60d413ed10047 /compiler | |
parent | 4bef5a7a78981bc8f5b8b3bd3f8c1c9de8533bb5 (diff) | |
download | Nim-019d6e4127a1dbe7ba8be4cc40c3c9358b1c48b3.tar.gz |
added missing type flags
Diffstat (limited to 'compiler')
-rwxr-xr-x | compiler/ast.nim | 14 | ||||
-rwxr-xr-x | compiler/semtypes.nim | 2 | ||||
-rwxr-xr-x | compiler/types.nim | 16 |
3 files changed, 21 insertions, 11 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim index 39228da40..edf93f4c9 100755 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -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: diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index 6716693ca..ab80298de 100755 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -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) diff --git a/compiler/types.nim b/compiler/types.nim index afc05d773..dbd03620c 100755 --- a/compiler/types.nim +++ b/compiler/types.nim @@ -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) |