added typetraits.supportsCopyMem

This commit is contained in:
Andreas Rumpf
2017-10-17 21:59:17 +02:00
parent 58d5f96790
commit e7f37d7223
2 changed files with 9 additions and 1 deletions

View File

@@ -146,8 +146,13 @@ proc evalTypeTrait(traitCall: PNode, operand: PType, context: PSym): PNode =
result = res.base.toNode(traitCall.info)
of "stripGenericParams":
result = uninstantiate(operand).toNode(traitCall.info)
of "supportsCopyMem":
let complexObj = containsGarbageCollectedRef(operand) or
hasDestructor(operand)
result = newIntNodeT(ord(not complexObj), traitCall)
else:
internalAssert false
localError(traitCall.info, "unknown trait")
result = emptyNode
proc semTypeTraits(c: PContext, n: PNode): PNode =
checkMinSonsLen(n, 2)

View File

@@ -49,3 +49,6 @@ proc stripGenericParams*(t: typedesc): typedesc {.magic: "TypeTrait".}
## This trait is similar to `genericHead`, but instead of producing
## error for non-generic types, it will just return them unmodified
proc supportsCopyMem*(t: typedesc): bool {.magic: "TypeTrait".}
## This trait returns true iff the type ``t`` is safe to use for
## `copyMem`:idx:. Other languages name a type like these `blob`:idx:.