Lineinfo change (#6084)

This commit is contained in:
Arne Döring 2017-07-17 08:12:15 +02:00 • committed by Andreas Rumpf
commit 52f092d02b
9 changed files with 53 additions and 12 deletions

View file

@ -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:

View file

@ -98,7 +98,7 @@ type
opcNError, opcNError,
opcNWarning, opcNWarning,
opcNHint, opcNHint,
opcNLineInfo, opcNGetLine, opcNGetColumn, opcNGetFile,
opcEqIdent, opcEqIdent,
opcStrToIdent, opcStrToIdent,
opcIdentToStr, opcIdentToStr,

View file

@ -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)

View file

@ -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.}