diff options
author | Peter Munch-Ellingsen <peterme@peterme.net> | 2022-12-22 04:34:36 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-22 04:34:36 +0100 |
commit | 613829f7a4da5506269fadb3acc78d64ee0cbddf (patch) | |
tree | 2b903c1ebf0f6f91f61c6faa5acce2d29b8640e9 /lib | |
parent | d0721eadf8cd6bf9436b5e5c9113c4c7bcfcc770 (diff) | |
download | Nim-613829f7a4da5506269fadb3acc78d64ee0cbddf.tar.gz |
Implement setLineInfo (#21153)
* Implement setLineInfo * Add tests
Diffstat (limited to 'lib')
-rw-r--r-- | lib/core/macros.nim | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/core/macros.nim b/lib/core/macros.nim index 18a70f20c..138ec47a0 100644 --- a/lib/core/macros.nim +++ b/lib/core/macros.nim @@ -533,6 +533,22 @@ proc getFile(arg: NimNode): string {.magic: "NLineInfo", noSideEffect.} proc copyLineInfo*(arg: NimNode, info: NimNode) {.magic: "NLineInfo", noSideEffect.} ## Copy lineinfo from `info`. +proc setLine(arg: NimNode, line: uint16) {.magic: "NLineInfo", noSideEffect.} +proc setColumn(arg: NimNode, column: int16) {.magic: "NLineInfo", noSideEffect.} +proc setFile(arg: NimNode, file: string) {.magic: "NLineInfo", noSideEffect.} + +proc setLineInfo*(arg: NimNode, file: string, line: int, column: int) = + ## Sets the line info on the NimNode. The file needs to exists, but can be a + ## relative path. If you want to attach line info to a block using `quote` + ## you'll need to add the line information after the quote block. + arg.setFile(file) + arg.setLine(line.uint16) + arg.setColumn(column.int16) + +proc setLineInfo*(arg: NimNode, lineInfo: LineInfo) = + ## See `setLineInfo proc<#setLineInfo,NimNode,string,int,int>`_ + setLineInfo(arg, lineInfo.filename, lineInfo.line, lineInfo.column) + proc lineInfoObj*(n: NimNode): LineInfo = ## Returns `LineInfo` of `n`, using absolute path for `filename`. result = LineInfo(filename: n.getFile, line: n.getLine, column: n.getColumn) |