Merge branch 'devel' into experimentalize-reorder
This commit is contained in:
commit
eb668003bf
241 changed files with 6388 additions and 12619 deletions
|
|
@ -71,6 +71,7 @@ const
|
|||
letPragmas* = varPragmas
|
||||
procTypePragmas* = {FirstCallConv..LastCallConv, wVarargs, wNosideeffect,
|
||||
wThread, wRaises, wLocks, wTags, wGcSafe}
|
||||
forVarPragmas* = {wInject, wGensym}
|
||||
allRoutinePragmas* = methodPragmas + iteratorPragmas + lambdaPragmas
|
||||
|
||||
proc getPragmaVal*(procAst: PNode; name: TSpecialWord): PNode =
|
||||
|
|
@ -95,7 +96,9 @@ const
|
|||
errIntLiteralExpected = "integer literal expected"
|
||||
|
||||
proc invalidPragma*(c: PContext; n: PNode) =
|
||||
localError(c.config, n.info, "invalid pragma: " % renderTree(n, {renderNoComments}))
|
||||
localError(c.config, n.info, "invalid pragma: " & renderTree(n, {renderNoComments}))
|
||||
proc illegalCustomPragma*(c: PContext, n: PNode, s: PSym) =
|
||||
localError(c.config, n.info, "cannot attach a custom pragma to '" & s.name.s & "'")
|
||||
|
||||
proc pragmaAsm*(c: PContext, n: PNode): char =
|
||||
result = '\0'
|
||||
|
|
@ -336,6 +339,20 @@ proc pragmaToOptions(w: TSpecialWord): TOptions {.inline.} =
|
|||
of wPatterns: {optPatterns}
|
||||
else: {}
|
||||
|
||||
proc processExperimental(c: PContext; n: PNode) =
|
||||
if n.kind notin nkPragmaCallKinds or n.len != 2:
|
||||
c.features.incl oldExperimentalFeatures
|
||||
else:
|
||||
n[1] = c.semConstExpr(c, n[1])
|
||||
case n[1].kind
|
||||
of nkStrLit, nkRStrLit, nkTripleStrLit:
|
||||
try:
|
||||
c.features.incl parseEnum[Feature](n[1].strVal)
|
||||
except ValueError:
|
||||
localError(c.config, n[1].info, "unknown experimental feature")
|
||||
else:
|
||||
localError(c.config, n.info, errStringLiteralExpected)
|
||||
|
||||
proc tryProcessOption(c: PContext, n: PNode, resOptions: var TOptions): bool =
|
||||
result = true
|
||||
if n.kind notin nkPragmaCallKinds or n.len != 2: result = false
|
||||
|
|
@ -343,6 +360,9 @@ proc tryProcessOption(c: PContext, n: PNode, resOptions: var TOptions): bool =
|
|||
elif n.sons[0].kind != nkIdent: result = false
|
||||
else:
|
||||
let sw = whichKeyword(n.sons[0].ident)
|
||||
if sw == wExperimental:
|
||||
processExperimental(c, n)
|
||||
return true
|
||||
let opts = pragmaToOptions(sw)
|
||||
if opts != {}:
|
||||
onOff(c, n, opts, resOptions)
|
||||
|
|
@ -381,6 +401,7 @@ proc processPush(c: PContext, n: PNode, start: int) =
|
|||
x.defaultCC = y.defaultCC
|
||||
x.dynlib = y.dynlib
|
||||
x.notes = c.config.notes
|
||||
x.features = c.features
|
||||
c.optionStack.add(x)
|
||||
for i in countup(start, sonsLen(n) - 1):
|
||||
if not tryProcessOption(c, n.sons[i], c.config.options):
|
||||
|
|
@ -400,6 +421,7 @@ proc processPop(c: PContext, n: PNode) =
|
|||
else:
|
||||
c.config.options = c.optionStack[^1].options
|
||||
c.config.notes = c.optionStack[^1].notes
|
||||
c.features = c.optionStack[^1].features
|
||||
c.optionStack.setLen(c.optionStack.len - 1)
|
||||
|
||||
proc processDefine(c: PContext, n: PNode) =
|
||||
|
|
@ -710,9 +732,7 @@ proc semCustomPragma(c: PContext, n: PNode): PNode =
|
|||
elif n.kind == nkExprColonExpr:
|
||||
result.kind = n.kind # pragma(arg) -> pragma: arg
|
||||
|
||||
proc processExperimental(c: PContext; n: PNode; s: PSym) =
|
||||
if not isTopLevel(c):
|
||||
localError(c.config, n.info, "'experimental' pragma only valid as toplevel statement")
|
||||
proc processExperimental(c: PContext; n: PNode) =
|
||||
if n.kind notin nkPragmaCallKinds or n.len != 2:
|
||||
c.features.incl oldExperimentalFeatures
|
||||
else:
|
||||
|
|
@ -1065,7 +1085,9 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int,
|
|||
else:
|
||||
it.sons[1] = c.semExpr(c, it.sons[1])
|
||||
of wExperimental:
|
||||
processExperimental(c, it, sym)
|
||||
if not isTopLevel(c):
|
||||
localError(c.config, n.info, "'experimental' pragma only valid as toplevel statement or in a 'push' environment")
|
||||
processExperimental(c, it)
|
||||
of wThis:
|
||||
if it.kind in nkPragmaCallKinds and it.len == 2:
|
||||
c.selfName = considerQuotedIdent(c, it[1])
|
||||
|
|
@ -1090,9 +1112,10 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int,
|
|||
else: sym.flags.incl sfUsed
|
||||
of wLiftLocals: discard
|
||||
else: invalidPragma(c, it)
|
||||
else:
|
||||
elif sym.kind in {skField,skProc,skFunc,skConverter,skMethod,skType}:
|
||||
n.sons[i] = semCustomPragma(c, it)
|
||||
|
||||
else:
|
||||
illegalCustomPragma(c, it, sym)
|
||||
|
||||
proc implicitPragmas*(c: PContext, sym: PSym, n: PNode,
|
||||
validPragmas: TSpecialWords) =
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue