sizeof alignof offsetof macros api (#10855)

This commit is contained in:
Arne Döring 2019-03-19 08:23:00 +01:00 • committed by Andreas Rumpf
commit 188870648a
7 changed files with 93 additions and 1 deletions

View file

@ -1582,3 +1582,15 @@ proc getProjectPath*(): string = discard
## Returns the path to the currently compiling project, not to
## be confused with ``system.currentSourcePath`` which returns
## the path of the current module.
when defined(nimMacrosSizealignof):
proc getSize*(arg: NimNode): int {.magic: "NSizeOf", noSideEffect.} =
## Returns the same result as ``system.sizeof``, but it works on
## ``NimNode`` for use in macro context.
proc getAlign*(arg: NimNode): int {.magic: "NSizeOf", noSideEffect.} =
## Returns the same result as ``system.alignof``, but it works on
## ``NimNode`` for use in macro context.
proc getOffset*(arg: NimNode): int {.magic: "NSizeOf", noSideEffect.} =
## Returns the same result as ``system.offsetof``, but it expects
## a resolved symbol node from a field of a type. Therefore it
## only requires one argument instead of two.