Lineinfo change (#6084)
This commit is contained in:
parent
9427724a71
commit
52f092d02b
9 changed files with 53 additions and 12 deletions
|
|
@ -746,7 +746,7 @@ proc toFileLine*(info: TLineInfo): string {.inline.} =
|
||||||
result = info.toFilename & ":" & $info.line
|
result = info.toFilename & ":" & $info.line
|
||||||
|
|
||||||
proc toFileLineCol*(info: TLineInfo): string {.inline.} =
|
proc toFileLineCol*(info: TLineInfo): string {.inline.} =
|
||||||
result = info.toFilename & "(" & $info.line & "," & $info.col & ")"
|
result = info.toFilename & "(" & $info.line & ", " & $info.col & ")"
|
||||||
|
|
||||||
proc `$`*(info: TLineInfo): string = toFileLineCol(info)
|
proc `$`*(info: TLineInfo): string = toFileLineCol(info)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1307,12 +1307,24 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
|
||||||
ensureKind(rkNode)
|
ensureKind(rkNode)
|
||||||
if c.callsite != nil: regs[ra].node = c.callsite
|
if c.callsite != nil: regs[ra].node = c.callsite
|
||||||
else: stackTrace(c, tos, pc, errFieldXNotFound, "callsite")
|
else: stackTrace(c, tos, pc, errFieldXNotFound, "callsite")
|
||||||
of opcNLineInfo:
|
of opcNGetFile:
|
||||||
decodeB(rkNode)
|
decodeB(rkNode)
|
||||||
let n = regs[rb].node
|
let n = regs[rb].node
|
||||||
createStr regs[ra]
|
regs[ra].node = newStrNode(nkStrLit, n.info.toFilename)
|
||||||
regs[ra].node.strVal = n.info.toFileLineCol
|
regs[ra].node.info = n.info
|
||||||
regs[ra].node.info = c.debug[pc]
|
regs[ra].node.typ = n.typ
|
||||||
|
of opcNGetLine:
|
||||||
|
decodeB(rkNode)
|
||||||
|
let n = regs[rb].node
|
||||||
|
regs[ra].node = newIntNode(nkIntLit, n.info.line)
|
||||||
|
regs[ra].node.info = n.info
|
||||||
|
regs[ra].node.typ = n.typ
|
||||||
|
of opcNGetColumn:
|
||||||
|
decodeB(rkNode)
|
||||||
|
let n = regs[rb].node
|
||||||
|
regs[ra].node = newIntNode(nkIntLit, n.info.col)
|
||||||
|
regs[ra].node.info = n.info
|
||||||
|
regs[ra].node.typ = n.typ
|
||||||
of opcEqIdent:
|
of opcEqIdent:
|
||||||
decodeBC(rkInt)
|
decodeBC(rkInt)
|
||||||
if regs[rb].node.kind == nkIdent and regs[rc].node.kind == nkIdent:
|
if regs[rb].node.kind == nkIdent and regs[rc].node.kind == nkIdent:
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,7 @@ type
|
||||||
opcNError,
|
opcNError,
|
||||||
opcNWarning,
|
opcNWarning,
|
||||||
opcNHint,
|
opcNHint,
|
||||||
opcNLineInfo,
|
opcNGetLine, opcNGetColumn, opcNGetFile,
|
||||||
opcEqIdent,
|
opcEqIdent,
|
||||||
opcStrToIdent,
|
opcStrToIdent,
|
||||||
opcIdentToStr,
|
opcIdentToStr,
|
||||||
|
|
|
||||||
|
|
@ -1071,7 +1071,16 @@ proc genMagic(c: PCtx; n: PNode; dest: var TDest; m: TMagic) =
|
||||||
of mEqIdent: genBinaryABC(c, n, dest, opcEqIdent)
|
of mEqIdent: genBinaryABC(c, n, dest, opcEqIdent)
|
||||||
of mEqNimrodNode: genBinaryABC(c, n, dest, opcEqNimrodNode)
|
of mEqNimrodNode: genBinaryABC(c, n, dest, opcEqNimrodNode)
|
||||||
of mSameNodeType: genBinaryABC(c, n, dest, opcSameNodeType)
|
of mSameNodeType: genBinaryABC(c, n, dest, opcSameNodeType)
|
||||||
of mNLineInfo: genUnaryABC(c, n, dest, opcNLineInfo)
|
of mNLineInfo:
|
||||||
|
case n[0].sym.name.s
|
||||||
|
of "getFile":
|
||||||
|
genUnaryABC(c, n, dest, opcNGetFile)
|
||||||
|
of "getLine":
|
||||||
|
genUnaryABC(c, n, dest, opcNGetLine)
|
||||||
|
of "getColumn":
|
||||||
|
genUnaryABC(c, n, dest, opcNGetColumn)
|
||||||
|
else:
|
||||||
|
internalAssert false
|
||||||
of mNHint:
|
of mNHint:
|
||||||
unused(n, dest)
|
unused(n, dest)
|
||||||
genUnaryStmt(c, n, opcNHint)
|
genUnaryStmt(c, n, opcNHint)
|
||||||
|
|
|
||||||
|
|
@ -317,10 +317,30 @@ proc toStrLit*(n: NimNode): NimNode {.compileTime.} =
|
||||||
## in a string literal node
|
## in a string literal node
|
||||||
return newStrLitNode(repr(n))
|
return newStrLitNode(repr(n))
|
||||||
|
|
||||||
proc lineinfo*(n: NimNode): string {.magic: "NLineInfo", noSideEffect.}
|
type
|
||||||
|
LineInfo* = object
|
||||||
|
filename*: string
|
||||||
|
line*,column*: int
|
||||||
|
|
||||||
|
proc `$`*(arg: Lineinfo): string =
|
||||||
|
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
|
## returns the position the node appears in the original source file
|
||||||
## in the form filename(line, col)
|
## in the form filename(line, col)
|
||||||
|
|
||||||
|
proc getLine(arg: NimNode): int {.magic: "NLineInfo", noSideEffect.}
|
||||||
|
proc getColumn(arg: NimNode): int {.magic: "NLineInfo", noSideEffect.}
|
||||||
|
proc getFile(arg: NimNode): string {.magic: "NLineInfo", noSideEffect.}
|
||||||
|
|
||||||
|
proc lineInfoObj*(n: NimNode): LineInfo {.compileTime.} =
|
||||||
|
result.filename = n.getFile
|
||||||
|
result.line = n.getLine
|
||||||
|
result.column = n.getColumn
|
||||||
|
|
||||||
|
proc lineInfo*(arg: NimNode): string {.compileTime.} =
|
||||||
|
$arg.lineInfoObj
|
||||||
|
|
||||||
proc internalParseExpr(s: string): NimNode {.
|
proc internalParseExpr(s: string): NimNode {.
|
||||||
magic: "ParseExprToAst", noSideEffect.}
|
magic: "ParseExprToAst", noSideEffect.}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
discard """
|
discard """
|
||||||
errormsg: "invalid declaration order; cannot attach 'step' to method defined here: tmapper.nim(22,7)"
|
errormsg: "invalid declaration order; cannot attach 'step' to method defined here: tmapper.nim(22, 7)"
|
||||||
line: 25
|
line: 25
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
discard """
|
discard """
|
||||||
line: 8
|
line: 8
|
||||||
errormsg: "public implementation 'tmismatchedvisibility.foo(a: int)[declared in tmismatchedvisibility.nim(6,5)]' has non-public forward declaration in "
|
errormsg: "public implementation 'tmismatchedvisibility.foo(a: int)[declared in tmismatchedvisibility.nim(6, 5)]' has non-public forward declaration in "
|
||||||
"""
|
"""
|
||||||
|
|
||||||
proc foo(a: int): int
|
proc foo(a: int): int
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
discard """
|
discard """
|
||||||
nimout: '''
|
nimout: '''
|
||||||
compile start
|
compile start
|
||||||
tused.nim(15, 8) Hint: 'tused.echoSub(a: int, b: int)[declared in tused.nim(15,7)]' is declared but not used [XDeclaredButNotUsed]
|
tused.nim(15, 8) Hint: 'tused.echoSub(a: int, b: int)[declared in tused.nim(15, 7)]' is declared but not used [XDeclaredButNotUsed]
|
||||||
compile end'''
|
compile end'''
|
||||||
output: "8\n8"
|
output: "8\n8"
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
discard """
|
discard """
|
||||||
outputsub: '''tquasiquote.nim(14,8): Check failed: 1 > 2'''
|
outputsub: '''tquasiquote.nim(14, 8): Check failed: 1 > 2'''
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import macros
|
import macros
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue