fix deprecation warnings in asyncmacro and htmlgen (#7573)

* fix deprecation warnings in asyncmacro and htmlgen

* removed todo
This commit is contained in:
Arne Döring 2018-04-12 13:54:49 +02:00 • committed by Andreas Rumpf
commit 84982e5e17
2 changed files with 22 additions and 21 deletions

View file

@ -179,7 +179,7 @@ proc processBody(node, retFutureSym: NimNode,
result.add newNimNode(nnkReturnStmt, node).add(newNilLit()) result.add newNimNode(nnkReturnStmt, node).add(newNilLit())
return # Don't process the children of this return stmt return # Don't process the children of this return stmt
of nnkCommand, nnkCall: of nnkCommand, nnkCall:
if node[0].kind == nnkIdent and node[0].ident == !"await": if node[0].kind == nnkIdent and node[0].eqIdent("await"):
case node[1].kind case node[1].kind
of nnkIdent, nnkInfix, nnkDotExpr, nnkCall, nnkCommand: of nnkIdent, nnkInfix, nnkDotExpr, nnkCall, nnkCommand:
# await x # await x
@ -192,7 +192,7 @@ proc processBody(node, retFutureSym: NimNode,
else: else:
error("Invalid node kind in 'await', got: " & $node[1].kind) error("Invalid node kind in 'await', got: " & $node[1].kind)
elif node.len > 1 and node[1].kind == nnkCommand and elif node.len > 1 and node[1].kind == nnkCommand and
node[1][0].kind == nnkIdent and node[1][0].ident == !"await": node[1][0].kind == nnkIdent and node[1][0].eqIdent("await"):
# foo await x # foo await x
var newCommand = node var newCommand = node
result.createVar("future" & $node[0].toStrLit, node[1][1], newCommand[1], result.createVar("future" & $node[0].toStrLit, node[1][1], newCommand[1],
@ -201,16 +201,16 @@ proc processBody(node, retFutureSym: NimNode,
of nnkVarSection, nnkLetSection: of nnkVarSection, nnkLetSection:
case node[0][2].kind case node[0][2].kind
of nnkCommand: of nnkCommand:
if node[0][2][0].kind == nnkIdent and node[0][2][0].ident == !"await": if node[0][2][0].kind == nnkIdent and node[0][2][0].eqIdent("await"):
# var x = await y # var x = await y
var newVarSection = node # TODO: Should this use copyNimNode? var newVarSection = node # TODO: Should this use copyNimNode?
result.createVar("future" & $node[0][0].ident, node[0][2][1], result.createVar("future" & node[0][0].strVal, node[0][2][1],
newVarSection[0][2], newVarSection, node) newVarSection[0][2], newVarSection, node)
else: discard else: discard
of nnkAsgn: of nnkAsgn:
case node[1].kind case node[1].kind
of nnkCommand: of nnkCommand:
if node[1][0].ident == !"await": if node[1][0].eqIdent("await"):
# x = await y # x = await y
var newAsgn = node var newAsgn = node
result.createVar("future" & $node[0].toStrLit, node[1][1], newAsgn[1], newAsgn, node) result.createVar("future" & $node[0].toStrLit, node[1][1], newAsgn[1], newAsgn, node)
@ -218,7 +218,7 @@ proc processBody(node, retFutureSym: NimNode,
of nnkDiscardStmt: of nnkDiscardStmt:
# discard await x # discard await x
if node[0].kind == nnkCommand and node[0][0].kind == nnkIdent and if node[0].kind == nnkCommand and node[0][0].kind == nnkIdent and
node[0][0].ident == !"await": node[0][0].eqIdent("await"):
var newDiscard = node var newDiscard = node
result.createVar("futureDiscard_" & $toStrLit(node[0][1]), node[0][1], result.createVar("futureDiscard_" & $toStrLit(node[0][1]), node[0][1],
newDiscard[0], newDiscard, node) newDiscard[0], newDiscard, node)
@ -283,9 +283,9 @@ proc processBody(node, retFutureSym: NimNode,
proc getName(node: NimNode): string {.compileTime.} = proc getName(node: NimNode): string {.compileTime.} =
case node.kind case node.kind
of nnkPostfix: of nnkPostfix:
return $node[1].ident return node[1].strVal
of nnkIdent: of nnkIdent:
return $node.ident return node.strVal
of nnkEmpty: of nnkEmpty:
return "anonymous" return "anonymous"
else: else:
@ -296,7 +296,7 @@ proc getFutureVarIdents(params: NimNode): seq[NimNode] {.compileTime.} =
for i in 1 ..< len(params): for i in 1 ..< len(params):
expectKind(params[i], nnkIdentDefs) expectKind(params[i], nnkIdentDefs)
if params[i][1].kind == nnkBracketExpr and if params[i][1].kind == nnkBracketExpr and
($params[i][1][0].ident).normalize == "futurevar": params[i][1][0].eqIdent("futurevar"):
result.add(params[i][0]) result.add(params[i][0])
proc isInvalidReturnType(typeName: string): bool = proc isInvalidReturnType(typeName: string): bool =
@ -323,7 +323,7 @@ proc asyncSingleProc(prc: NimNode): NimNode {.compileTime.} =
let fut = repr(returnType[0]) let fut = repr(returnType[0])
verifyReturnType(fut) verifyReturnType(fut)
baseType = returnType[1] baseType = returnType[1]
elif returnType.kind in nnkCallKinds and $returnType[0] == "[]": elif returnType.kind in nnkCallKinds and returnType[0].eqIdent("[]"):
let fut = repr(returnType[1]) let fut = repr(returnType[1])
verifyReturnType(fut) verifyReturnType(fut)
baseType = returnType[2] baseType = returnType[2]
@ -333,7 +333,7 @@ proc asyncSingleProc(prc: NimNode): NimNode {.compileTime.} =
verifyReturnType(repr(returnType)) verifyReturnType(repr(returnType))
let subtypeIsVoid = returnType.kind == nnkEmpty or let subtypeIsVoid = returnType.kind == nnkEmpty or
(baseType.kind == nnkIdent and returnType[1].ident == !"void") (baseType.kind == nnkIdent and returnType[1].eqIdent("void"))
let futureVarIdents = getFutureVarIdents(prc.params) let futureVarIdents = getFutureVarIdents(prc.params)
@ -348,7 +348,7 @@ proc asyncSingleProc(prc: NimNode): NimNode {.compileTime.} =
newVarStmt(retFutureSym, newVarStmt(retFutureSym,
newCall( newCall(
newNimNode(nnkBracketExpr, prc.body).add( newNimNode(nnkBracketExpr, prc.body).add(
newIdentNode(!"newFuture"), # TODO: Strange bug here? Remove the `!`. newIdentNode("newFuture"),
subRetType), subRetType),
newLit(prcName)))) # Get type from return type of this proc newLit(prcName)))) # Get type from return type of this proc
@ -448,30 +448,30 @@ proc stripAwait(node: NimNode): NimNode =
case node.kind case node.kind
of nnkCommand, nnkCall: of nnkCommand, nnkCall:
if node[0].kind == nnkIdent and node[0].ident == !"await": if node[0].kind == nnkIdent and node[0].eqIdent("await"):
node[0] = emptyNoopSym node[0] = emptyNoopSym
elif node.len > 1 and node[1].kind == nnkCommand and elif node.len > 1 and node[1].kind == nnkCommand and
node[1][0].kind == nnkIdent and node[1][0].ident == !"await": node[1][0].kind == nnkIdent and node[1][0].eqIdent("await"):
# foo await x # foo await x
node[1][0] = emptyNoopSym node[1][0] = emptyNoopSym
of nnkVarSection, nnkLetSection: of nnkVarSection, nnkLetSection:
case node[0][2].kind case node[0][2].kind
of nnkCommand: of nnkCommand:
if node[0][2][0].kind == nnkIdent and node[0][2][0].ident == !"await": if node[0][2][0].kind == nnkIdent and node[0][2][0].eqIdent("await"):
# var x = await y # var x = await y
node[0][2][0] = emptyNoopSym node[0][2][0] = emptyNoopSym
else: discard else: discard
of nnkAsgn: of nnkAsgn:
case node[1].kind case node[1].kind
of nnkCommand: of nnkCommand:
if node[1][0].ident == !"await": if node[1][0].eqIdent("await"):
# x = await y # x = await y
node[1][0] = emptyNoopSym node[1][0] = emptyNoopSym
else: discard else: discard
of nnkDiscardStmt: of nnkDiscardStmt:
# discard await x # discard await x
if node[0].kind == nnkCommand and node[0][0].kind == nnkIdent and if node[0].kind == nnkCommand and node[0][0].kind == nnkIdent and
node[0][0].ident == !"await": node[0][0].eqIdent("await"):
node[0][0] = emptyNoopSym node[0][0] = emptyNoopSym
else: discard else: discard
@ -480,9 +480,9 @@ proc stripAwait(node: NimNode): NimNode =
proc splitParamType(paramType: NimNode, async: bool): NimNode = proc splitParamType(paramType: NimNode, async: bool): NimNode =
result = paramType result = paramType
if paramType.kind == nnkInfix and $paramType[0].ident in ["|", "or"]: if paramType.kind == nnkInfix and paramType[0].strVal in ["|", "or"]:
let firstAsync = "async" in ($paramType[1].ident).normalize let firstAsync = "async" in paramType[1].strVal.normalize
let secondAsync = "async" in ($paramType[2].ident).normalize let secondAsync = "async" in paramType[2].strVal.normalize
if firstAsync: if firstAsync:
result = paramType[if async: 1 else: 2] result = paramType[if async: 1 else: 2]

View file

@ -38,7 +38,8 @@ const
proc getIdent(e: NimNode): string {.compileTime.} = proc getIdent(e: NimNode): string {.compileTime.} =
case e.kind case e.kind
of nnkIdent: result = normalize($e.ident) of nnkIdent:
result = e.strVal.normalize
of nnkAccQuoted: of nnkAccQuoted:
result = getIdent(e[0]) result = getIdent(e[0])
for i in 1 .. e.len-1: for i in 1 .. e.len-1: