diff options
author | Arne Döring <arne.doering@gmx.net> | 2019-11-13 09:22:41 +0100 |
---|---|---|
committer | cooldome <cdome@bk.ru> | 2019-11-13 08:22:41 +0000 |
commit | 0496a666e22465eba9a309f0974220988f7f9920 (patch) | |
tree | d8393dceb5064a0f6bc1331d89759bb18a1a6a0c /compiler/pragmas.nim | |
parent | 84861eb48a1a7aa400b05a39b1d1dc1fc745aed2 (diff) | |
download | Nim-0496a666e22465eba9a309f0974220988f7f9920.tar.gz |
implemented alignas pragma (#12643)
* implemented alignas pragma * fix bootstrap * generate c++ compatible syntax for alignas * Make it work. * Multiple alignof expressions. Implement top level alignof.
Diffstat (limited to 'compiler/pragmas.nim')
-rw-r--r-- | compiler/pragmas.nim | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim index 205ed4309..24394bf97 100644 --- a/compiler/pragmas.nim +++ b/compiler/pragmas.nim @@ -20,7 +20,7 @@ const const declPragmas = {wImportc, wImportObjC, wImportCpp, wImportJs, wExportc, wExportCpp, - wExportNims, wExtern, wDeprecated, wNodecl, wError, wUsed} + wExportNims, wExtern, wDeprecated, wNodecl, wError, wUsed, wAlignas} ## common pragmas for declarations, to a good approximation procPragmas* = declPragmas + {FirstCallConv..LastCallConv, wMagic, wNoSideEffect, wSideEffect, wNoreturn, wDynlib, wHeader, @@ -803,13 +803,6 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int, setExternName(c, sym, name, it.info) of wImportObjC: processImportObjC(c, sym, getOptionalStr(c, it, "$1"), it.info) - of wAlign: - if sym.typ == nil: invalidPragma(c, it) - var align = expectIntLit(c, it) - if (not isPowerOfTwo(align) and align != 0) or align >% high(int16): - localError(c.config, it.info, "power of two expected") - else: - sym.typ.align = align.int16 of wSize: if sym.typ == nil: invalidPragma(c, it) var size = expectIntLit(c, it) @@ -822,6 +815,14 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int, sym.typ.align = floatInt64Align(c.config) else: localError(c.config, it.info, "size may only be 1, 2, 4 or 8") + of wAlignas: + let alignment = expectIntLit(c, it) + if alignment == 0: + discard + elif isPowerOfTwo(alignment): + sym.alignment = max(sym.alignment, alignment) + else: + localError(c.config, it.info, "power of two or 0 expected") of wNodecl: noVal(c, it) incl(sym.loc.flags, lfNoDecl) |