diff options
Diffstat (limited to 'compiler/semmagic.nim')
-rw-r--r-- | compiler/semmagic.nim | 47 |
1 files changed, 3 insertions, 44 deletions
diff --git a/compiler/semmagic.nim b/compiler/semmagic.nim index 1472cd2f3..6956e9eca 100644 --- a/compiler/semmagic.nim +++ b/compiler/semmagic.nim @@ -375,52 +375,11 @@ proc magicsAfterOverloadResolution(c: PContext, n: PNode, of mTypeOf: result = semTypeOf(c, n) of mSizeOf: - # TODO there is no proper way to find out if a type cannot be queried for the size. - let size = getSize(c.config, n[1].typ) - # We just assume here that the type might come from the c backend - if size == szUnknownSize: - # Forward to the c code generation to emit a `sizeof` in the C code. - result = n - elif size >= 0: - result = newIntNode(nkIntLit, size) - result.info = n.info - result.typ = n.typ - else: - localError(c.config, n.info, "cannot evaluate 'sizeof' because its type is not defined completely, type: " & n[1].typ.typeToString) - result = n + result = foldSizeOf(c.config, n, n) of mAlignOf: - # this is 100% analog to mSizeOf, could be made more dry. - let align = getAlign(c.config, n[1].typ) - if align == szUnknownSize: - result = n - elif align >= 0: - result = newIntNode(nkIntLit, align) - result.info = n.info - result.typ = n.typ - else: - localError(c.config, n.info, "cannot evaluate 'alignof' because its type is not defined completely, type: " & n[1].typ.typeToString) - result = n + result = foldAlignOf(c.config, n, n) of mOffsetOf: - var dotExpr: PNode - - block findDotExpr: - if n[1].kind == nkDotExpr: - dotExpr = n[1] - elif n[1].kind == nkCheckedFieldExpr: - dotExpr = n[1][0] - else: - illFormedAst(n, c.config) - - assert dotExpr != nil - - let value = dotExpr[0] - let member = dotExpr[1] - - discard computeSize(c.config, value.typ) - - result = newIntNode(nkIntLit, member.sym.offset) - result.info = n.info - result.typ = n.typ + result = foldOffsetOf(c.config, n, n) of mArrGet: result = semArrGet(c, n, flags) of mArrPut: |