Clean up macros (#14959)

This commit is contained in:
Juan Carlos
2020-07-14 11:44:56 -03:00
committed by GitHub
parent 2b0e336c97
commit 9465b5db44
8 changed files with 6 additions and 43 deletions

View File

@@ -139,7 +139,7 @@
- Tables, HashSets, SharedTables and deques don't require anymore that the passed
initial size must be a power of two - this is done internally.
Proc `rightSize` for Tables and HashSets is deprecated, as it is not needed anymore.
- Removed deprecated symbols from `macros` module, deprecated as far back as `0.15`.
## Language changes

View File

@@ -33,7 +33,7 @@ macro optFormat{`%`(f, a)}(f: string{lit}, a: openArray[string]): untyped =
#newCall("&")
let f = f.strVal
formatImpl(newLit)
result = nestList(!"&", result)
result = nestList(newIdentNode("&"), result)
template optAdd1{x = y; add(x, z)}(x, y, z: string) =
x = y & z

View File

@@ -140,10 +140,6 @@ const
{.push warnings: off.}
proc `!`*(s: string): NimIdent {.magic: "StrToIdent", noSideEffect, deprecated:
"Deprecated since version 0.18.0: Use 'ident' or 'newIdentNode' instead.".}
## Constructs an identifier from the string `s`.
proc toNimIdent*(s: string): NimIdent {.magic: "StrToIdent", noSideEffect, deprecated:
"Deprecated since version 0.18.0: Use 'ident' or 'newIdentNode' instead.".}
## Constructs an identifier from the string `s`.
@@ -393,13 +389,6 @@ proc `ident=`*(n: NimNode, val: NimIdent) {.magic: "NSetIdent", noSideEffect, de
{.pop.}
#proc `typ=`*(n: NimNode, typ: typedesc) {.magic: "NSetType".}
# this is not sound! Unfortunately forbidding 'typ=' is not enough, as you
# can easily do:
# let bracket = semCheck([1, 2])
# let fake = semCheck(2.0)
# bracket[0] = fake # constructs a mixed array with ints and floats!
proc `strVal=`*(n: NimNode, val: string) {.magic: "NSetStrVal", noSideEffect.}
## Sets the string value of a string literal or comment.
## Setting `strVal` is disallowed for `nnkIdent` and `nnkSym` nodes; a new node
@@ -830,14 +819,6 @@ proc nestList*(op: NimNode; pack: NimNode; init: NimNode): NimNode {.compileTime
for i in countdown(pack.len - 1, 0):
result = newCall(op, pack[i], result)
{.push warnings: off.}
proc nestList*(theProc: NimIdent, x: NimNode): NimNode {.compileTime, deprecated:
"Deprecated since v0.18.1; use one of 'nestList(NimNode, ...)' instead.".} =
nestList(newIdentNode(theProc), x)
{.pop.}
proc treeTraverse(n: NimNode; res: var string; level = 0; isLisp = false, indented = false) {.benign.} =
if level > 0:
if indented:
@@ -1628,21 +1609,6 @@ macro getCustomPragmaVal*(n: typed, cp: typed{nkSym}): untyped =
if result.kind == nnkEmpty:
error(n.repr & " doesn't have a pragma named " & cp.repr()) # returning an empty node results in most cases in a cryptic error,
when not defined(booting):
template emit*(e: static[string]): untyped {.deprecated.} =
## Accepts a single string argument and treats it as nim code
## that should be inserted verbatim in the program
## Example:
##
## .. code-block:: nim
## emit("echo " & '"' & "hello world".toUpper & '"')
##
## Deprecated since version 0.15 since it's so rarely useful.
macro payload: untyped {.gensym.} =
result = parseStmt(e)
payload()
macro unpackVarargs*(callee: untyped; args: varargs[untyped]): untyped =
result = newCall(callee)
for i in 0 ..< args.len:

View File

@@ -678,7 +678,7 @@ macro check*(conditions: untyped): untyped =
result = newNimNode(nnkStmtList)
for node in checked:
if node.kind != nnkCommentStmt:
result.add(newCall(!"check", node))
result.add(newCall(newIdentNode("check"), node))
else:
let lineinfo = newStrLitNode(checked.lineInfo)

View File

@@ -9,7 +9,7 @@ var packages2*: seq[tuple[name, cmd: string; hasDeps: bool; url: string, useHead
# packages A-M
pkg1 "alea", true
# pkg1 "alea", true
pkg1 "argparse"
pkg1 "arraymancer", true, "nim c tests/tests_cpu.nim"
pkg1 "ast_pattern_matching", false, "nim c -r --oldgensym:on tests/test1.nim"

View File

@@ -1,6 +1,5 @@
discard """
output: '''
HELLO WORLD
c_func
12
'''
@@ -8,8 +7,6 @@ c_func
import macros, strutils
emit("echo " & '"' & "hello world".toUpperAscii & '"')
# bug #1025
macro foo(icname): untyped =

View File

@@ -37,7 +37,7 @@ macro optFormat{`%`(f, a)}(f: string{lit}, a: openArray[string]): untyped =
result = newNimNode(nnkBracket)
let f = f.strVal
formatImpl(newLit)
result = nestList(!"&", result)
result = nestList(newIdentNode("&"), result)
template optAdd1{x = y; add(x, z)}(x, y, z: string) =
x = y & z

View File

@@ -38,7 +38,7 @@ macro autoClose(args: varargs[untyped]): untyped =
varAssignment.add(varValue)
variables.add(varAssignment)
closingCalls.add(newCall(!"close", varName))
closingCalls.add(newCall(newIdentNode("close"), varName))
else:
error "Using statement: Unexpected expression. Got " &
$args[i].kind & " instead of assignment."