diff options
author | Arne Döring <arne.doering@gmx.net> | 2019-03-19 08:23:00 +0100 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2019-03-19 08:23:00 +0100 |
commit | 188870648a002175a5ef4ef3df27fcc9404d750f (patch) | |
tree | 919d3198ef79605e8a5f5d8e46f4295013462e71 /lib/core | |
parent | 16fcbee1bcb810e032ddb6fd198e5a53987180af (diff) | |
download | Nim-188870648a002175a5ef4ef3df27fcc9404d750f.tar.gz |
sizeof alignof offsetof macros api (#10855)
Diffstat (limited to 'lib/core')
-rw-r--r-- | lib/core/macros.nim | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/core/macros.nim b/lib/core/macros.nim index b7d0f40f4..e48df38f5 100644 --- a/lib/core/macros.nim +++ b/lib/core/macros.nim @@ -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. |