diff options
author | Arne Döring <arne.doering@gmx.net> | 2017-07-17 08:12:15 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2017-07-17 08:12:15 +0200 |
commit | 52f092d02b5a4afa8cbd591bab9160e671f71700 (patch) | |
tree | 014875d219163f285d9e00137dcd19de0e106e79 | |
parent | 9427724a718ece9396d85fe8fa6a604b59f6bfd7 (diff) | |
download | Nim-52f092d02b5a4afa8cbd591bab9160e671f71700.tar.gz |
Lineinfo change (#6084)
-rw-r--r-- | compiler/msgs.nim | 2 | ||||
-rw-r--r-- | compiler/vm.nim | 20 | ||||
-rw-r--r-- | compiler/vmdef.nim | 2 | ||||
-rw-r--r-- | compiler/vmgen.nim | 11 | ||||
-rw-r--r-- | lib/core/macros.nim | 22 | ||||
-rw-r--r-- | tests/method/tmapper.nim | 2 | ||||
-rw-r--r-- | tests/modules/tmismatchedvisibility.nim | 2 | ||||
-rw-r--r-- | tests/pragmas/tused.nim | 2 | ||||
-rw-r--r-- | tests/showoff/tquasiquote.nim | 2 |
9 files changed, 53 insertions, 12 deletions
diff --git a/compiler/msgs.nim b/compiler/msgs.nim index 5f4a0caf1..4a1166f51 100644 --- a/compiler/msgs.nim +++ b/compiler/msgs.nim @@ -746,7 +746,7 @@ proc toFileLine*(info: TLineInfo): string {.inline.} = result = info.toFilename & ":" & $info.line 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) diff --git a/compiler/vm.nim b/compiler/vm.nim index b8e6467b5..908bbeb69 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -1307,12 +1307,24 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg = ensureKind(rkNode) if c.callsite != nil: regs[ra].node = c.callsite else: stackTrace(c, tos, pc, errFieldXNotFound, "callsite") - of opcNLineInfo: + of opcNGetFile: decodeB(rkNode) let n = regs[rb].node - createStr regs[ra] - regs[ra].node.strVal = n.info.toFileLineCol - regs[ra].node.info = c.debug[pc] + regs[ra].node = newStrNode(nkStrLit, n.info.toFilename) + regs[ra].node.info = n.info + 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: decodeBC(rkInt) if regs[rb].node.kind == nkIdent and regs[rc].node.kind == nkIdent: diff --git a/compiler/vmdef.nim b/compiler/vmdef.nim index 263ec8378..5045f3f07 100644 --- a/compiler/vmdef.nim +++ b/compiler/vmdef.nim @@ -98,7 +98,7 @@ type opcNError, opcNWarning, opcNHint, - opcNLineInfo, + opcNGetLine, opcNGetColumn, opcNGetFile, opcEqIdent, opcStrToIdent, opcIdentToStr, diff --git a/compiler/vmgen.nim b/compiler/vmgen.nim index ba89f88d4..d65fe22e9 100644 --- a/compiler/vmgen.nim +++ b/compiler/vmgen.nim @@ -1071,7 +1071,16 @@ proc genMagic(c: PCtx; n: PNode; dest: var TDest; m: TMagic) = of mEqIdent: genBinaryABC(c, n, dest, opcEqIdent) of mEqNimrodNode: genBinaryABC(c, n, dest, opcEqNimrodNode) 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: unused(n, dest) genUnaryStmt(c, n, opcNHint) diff --git a/lib/core/macros.nim b/lib/core/macros.nim index cdc91ce2b..3473c5d7e 100644 --- a/lib/core/macros.nim +++ b/lib/core/macros.nim @@ -317,10 +317,30 @@ proc toStrLit*(n: NimNode): NimNode {.compileTime.} = ## in a string literal node 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 ## 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 {. magic: "ParseExprToAst", noSideEffect.} diff --git a/tests/method/tmapper.nim b/tests/method/tmapper.nim index 0008d9033..a5d03f700 100644 --- a/tests/method/tmapper.nim +++ b/tests/method/tmapper.nim @@ -1,5 +1,5 @@ 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 """ diff --git a/tests/modules/tmismatchedvisibility.nim b/tests/modules/tmismatchedvisibility.nim index 91b639a27..2e8636d1e 100644 --- a/tests/modules/tmismatchedvisibility.nim +++ b/tests/modules/tmismatchedvisibility.nim @@ -1,6 +1,6 @@ discard """ 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 diff --git a/tests/pragmas/tused.nim b/tests/pragmas/tused.nim index 389863aef..83c62b7bb 100644 --- a/tests/pragmas/tused.nim +++ b/tests/pragmas/tused.nim @@ -1,7 +1,7 @@ discard """ nimout: ''' 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''' output: "8\n8" """ diff --git a/tests/showoff/tquasiquote.nim b/tests/showoff/tquasiquote.nim index df7fccc33..ebe004a92 100644 --- a/tests/showoff/tquasiquote.nim +++ b/tests/showoff/tquasiquote.nim @@ -1,5 +1,5 @@ discard """ - outputsub: '''tquasiquote.nim(14,8): Check failed: 1 > 2''' + outputsub: '''tquasiquote.nim(14, 8): Check failed: 1 > 2''' """ import macros |