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.
This commit is contained in:
Arne Döring 2019-11-13 09:22:41 +01:00 • committed by cooldome
commit 0496a666e2
13 changed files with 153 additions and 19 deletions

View file

@ -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)