mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-05 04:27:44 +00:00
Less warnings in macros (#10799)
This commit is contained in:
committed by
Andreas Rumpf
parent
06f23572d0
commit
35aab357e2
@@ -540,10 +540,6 @@ proc markUsed(conf: ConfigRef; info: TLineInfo; s: PSym; usageSym: var PSym) =
|
||||
when defined(nimsuggest):
|
||||
suggestSym(conf, info, s, usageSym, false)
|
||||
|
||||
proc useSym*(conf: ConfigRef; sym: PSym; usageSym: var PSym): PNode =
|
||||
result = newSymNode(sym)
|
||||
markUsed(conf, result.info, sym, usageSym)
|
||||
|
||||
proc safeSemExpr*(c: PContext, n: PNode): PNode =
|
||||
# use only for idetools support!
|
||||
try:
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#
|
||||
|
||||
include "system/inclrtl"
|
||||
include "system/helpers"
|
||||
|
||||
## This module contains the interface to the compiler's abstract syntax
|
||||
## tree (`AST`:idx:). Macros operate on this tree.
|
||||
@@ -121,7 +120,7 @@ type
|
||||
TNimSymKinds* {.deprecated.} = set[NimSymKind]
|
||||
|
||||
type
|
||||
NimIdent* = object of RootObj
|
||||
NimIdent* {.deprecated.} = object of RootObj
|
||||
## represents a Nim identifier in the AST. **Note**: This is only
|
||||
## rarely useful, for identifier construction from a string
|
||||
## use ``ident"abc"``.
|
||||
@@ -138,6 +137,8 @@ const
|
||||
nnkCallStrLit}
|
||||
nnkPragmaCallKinds = {nnkExprColonExpr, nnkCall, nnkCallStrLit}
|
||||
|
||||
{.push warnings: off.}
|
||||
|
||||
proc `!`*(s: string): NimIdent {.magic: "StrToIdent", noSideEffect, deprecated.}
|
||||
## constructs an identifier from the string `s`
|
||||
## **Deprecated since version 0.18.0**: Use ``ident`` or ``newIdentNode`` instead.
|
||||
@@ -157,6 +158,7 @@ proc `==`*(a, b: NimSym): bool {.magic: "EqNimrodNode", noSideEffect, deprecated
|
||||
## compares two Nim symbols
|
||||
## **Deprecated since version 0.18.1**; Use ``==(NimNode, NimNode)`` instead.
|
||||
|
||||
{.pop.}
|
||||
|
||||
proc sameType*(a, b: NimNode): bool {.magic: "SameNodeType", noSideEffect.} =
|
||||
## compares two Nim nodes' types. Return true if the types are the same,
|
||||
@@ -227,6 +229,8 @@ proc intVal*(n: NimNode): BiggestInt {.magic: "NIntVal", noSideEffect.}
|
||||
|
||||
proc floatVal*(n: NimNode): BiggestFloat {.magic: "NFloatVal", noSideEffect.}
|
||||
|
||||
{.push warnings: off.}
|
||||
|
||||
proc ident*(n: NimNode): NimIdent {.magic: "NIdent", noSideEffect, deprecated.} =
|
||||
## **Deprecated since version 0.18.1**; All functionality is defined on ``NimNode``.
|
||||
|
||||
@@ -268,6 +272,8 @@ else: # bootstrapping substitute
|
||||
else:
|
||||
n.strValOld
|
||||
|
||||
{.pop.}
|
||||
|
||||
when defined(nimSymImplTransform):
|
||||
proc getImplTransformed*(symbol: NimNode): NimNode {.magic: "GetImplTransf", noSideEffect.}
|
||||
## for a typed proc returns the AST after transformation pass
|
||||
@@ -360,12 +366,16 @@ proc getTypeImpl*(n: typedesc): NimNode {.magic: "NGetType", noSideEffect.}
|
||||
proc `intVal=`*(n: NimNode, val: BiggestInt) {.magic: "NSetIntVal", noSideEffect.}
|
||||
proc `floatVal=`*(n: NimNode, val: BiggestFloat) {.magic: "NSetFloatVal", noSideEffect.}
|
||||
|
||||
{.push warnings: off.}
|
||||
|
||||
proc `symbol=`*(n: NimNode, val: NimSym) {.magic: "NSetSymbol", noSideEffect, deprecated.}
|
||||
## **Deprecated since version 0.18.1**; Generate a new ``NimNode`` with ``genSym`` instead.
|
||||
|
||||
proc `ident=`*(n: NimNode, val: NimIdent) {.magic: "NSetIdent", noSideEffect, deprecated.}
|
||||
## **Deprecated since version 0.18.1**; Generate a new ``NimNode`` with ``ident(string)`` instead.
|
||||
|
||||
{.pop.}
|
||||
|
||||
#proc `typ=`*(n: NimNode, typ: typedesc) {.magic: "NSetType".}
|
||||
# this is not sound! Unfortunately forbidding 'typ=' is not enough, as you
|
||||
# can easily do:
|
||||
@@ -418,15 +428,20 @@ proc newFloatLitNode*(f: BiggestFloat): NimNode {.compileTime.} =
|
||||
result = newNimNode(nnkFloatLit)
|
||||
result.floatVal = f
|
||||
|
||||
proc newIdentNode*(i: NimIdent): NimNode {.compileTime.} =
|
||||
{.push warnings: off.}
|
||||
|
||||
proc newIdentNode*(i: NimIdent): NimNode {.compileTime, deprecated.} =
|
||||
## creates an identifier node from `i`
|
||||
result = newNimNode(nnkIdent)
|
||||
result.ident = i
|
||||
|
||||
{.pop.}
|
||||
|
||||
proc newIdentNode*(i: string): NimNode {.magic: "StrToIdent", noSideEffect.}
|
||||
## creates an identifier node from `i`. It is simply an alias for
|
||||
## ``ident(string)``. Use that, it's shorter.
|
||||
|
||||
|
||||
type
|
||||
BindSymRule* = enum ## specifies how ``bindSym`` behaves
|
||||
brClosed, ## only the symbols in current scope are bound
|
||||
@@ -478,7 +493,7 @@ type
|
||||
|
||||
proc `$`*(arg: Lineinfo): string =
|
||||
# BUG: without `result = `, gives compile error
|
||||
result = lineInfoToString(arg.filename, arg.line, arg.column)
|
||||
result = arg.filename & "(" & $arg.line & ", " & $arg.column & ")"
|
||||
|
||||
#proc lineinfo*(n: NimNode): LineInfo {.magic: "NLineInfo", noSideEffect.}
|
||||
## returns the position the node appears in the original source file
|
||||
@@ -603,6 +618,8 @@ proc newCall*(theProc: NimNode,
|
||||
result.add(theProc)
|
||||
result.add(args)
|
||||
|
||||
{.push warnings: off.}
|
||||
|
||||
proc newCall*(theProc: NimIdent,
|
||||
args: varargs[NimNode]): NimNode {.compileTime, deprecated.} =
|
||||
## produces a new call node. `theProc` is the proc that is called with
|
||||
@@ -613,6 +630,8 @@ proc newCall*(theProc: NimIdent,
|
||||
result.add(newIdentNode(theProc))
|
||||
result.add(args)
|
||||
|
||||
{.pop.}
|
||||
|
||||
proc newCall*(theProc: string,
|
||||
args: varargs[NimNode]): NimNode {.compileTime.} =
|
||||
## produces a new call node. `theProc` is the proc that is called with
|
||||
@@ -770,12 +789,13 @@ 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 version 0.18.1**; Use one of ``nestList(NimNode, ...)`` instead.
|
||||
var L = x.len
|
||||
result = newCall(theProc, x[L-2], x[L-1])
|
||||
for i in countdown(L-3, 0):
|
||||
result = newCall(theProc, x[i], result)
|
||||
nestList(newIdentNode(theProc), x)
|
||||
|
||||
{.pop.}
|
||||
|
||||
proc treeTraverse(n: NimNode; res: var string; level = 0; isLisp = false, indented = false) {.benign.} =
|
||||
if level > 0:
|
||||
@@ -1276,8 +1296,10 @@ proc basename*(a: NimNode): NimNode =
|
||||
|
||||
proc `basename=`*(a: NimNode; val: string) {.compileTime.}=
|
||||
case a.kind
|
||||
of nnkIdent: macros.`ident=`(a, toNimIdent val)
|
||||
of nnkPostfix, nnkPrefix: a[1] = ident(val)
|
||||
of nnkIdent:
|
||||
a.strVal = val
|
||||
of nnkPostfix, nnkPrefix:
|
||||
a[1] = ident(val)
|
||||
else:
|
||||
quit "Do not know how to get basename of (" & treeRepr(a) & ")\n" & repr(a)
|
||||
|
||||
|
||||
@@ -1,17 +1,9 @@
|
||||
# helpers used system.nim and other modules, avoids code duplication while
|
||||
# also minimizing symbols exposed in system.nim
|
||||
#
|
||||
# TODO: move other things here that should not be exposed in system.nim
|
||||
|
||||
proc lineInfoToString(file: string, line, column: int): string =
|
||||
file & "(" & $line & ", " & $column & ")"
|
||||
# TODO: remove this file. It causes "declared but not used" warnings everywhere.
|
||||
|
||||
type InstantiationInfo = tuple[filename: string, line: int, column: int]
|
||||
|
||||
proc `$`(info: InstantiationInfo): string =
|
||||
# The +1 is needed here
|
||||
# instead of overriding `$` (and changing its meaning), consider explicit name.
|
||||
lineInfoToString(info.fileName, info.line, info.column+1)
|
||||
info.fileName & "(" & $info.line & ", " & $(info.column+1) & ")"
|
||||
|
||||
proc isNamedTuple(T: type): bool =
|
||||
## return true for named tuples, false for any other type.
|
||||
|
||||
Reference in New Issue
Block a user