Implement setLineInfo (#21153)

* Implement setLineInfo

* Add tests
This commit is contained in:
Peter Munch-Ellingsen 2022-12-22 04:34:36 +01:00 • committed by GitHub
commit 613829f7a4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 72 additions and 5 deletions

View file

@ -128,6 +128,13 @@ proc fileInfoIdx*(conf: ConfigRef; filename: AbsoluteFile): FileIndex =
var dummy: bool
result = fileInfoIdx(conf, filename, dummy)
proc fileInfoIdx*(conf: ConfigRef; filename: RelativeFile; isKnownFile: var bool): FileIndex =
fileInfoIdx(conf, AbsoluteFile expandFilename(filename.string), isKnownFile)
proc fileInfoIdx*(conf: ConfigRef; filename: RelativeFile): FileIndex =
var dummy: bool
fileInfoIdx(conf, AbsoluteFile expandFilename(filename.string), dummy)
proc newLineInfo*(fileInfoIdx: FileIndex, line, col: int): TLineInfo =
result.fileIndex = fileInfoIdx
if line < int high(uint16):

View file

@ -1934,14 +1934,24 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
of 1: # getLine
regs[ra].node = newIntNode(nkIntLit, n.info.line.int)
of 2: # getColumn
regs[ra].node = newIntNode(nkIntLit, n.info.col)
regs[ra].node = newIntNode(nkIntLit, n.info.col.int)
else:
internalAssert c.config, false
regs[ra].node.info = n.info
regs[ra].node.typ = n.typ
of opcNSetLineInfo:
of opcNCopyLineInfo:
decodeB(rkNode)
regs[ra].node.info = regs[rb].node.info
of opcNSetLineInfoLine:
decodeB(rkNode)
regs[ra].node.info.line = regs[rb].intVal.uint16
of opcNSetLineInfoColumn:
decodeB(rkNode)
regs[ra].node.info.col = regs[rb].intVal.int16
of opcNSetLineInfoFile:
decodeB(rkNode)
regs[ra].node.info.fileIndex =
fileInfoIdx(c.config, RelativeFile regs[rb].node.strVal)
of opcEqIdent:
decodeBC(rkInt)
# aliases for shorter and easier to understand code below

View file

@ -141,7 +141,8 @@ type
opcNError,
opcNWarning,
opcNHint,
opcNGetLineInfo, opcNSetLineInfo,
opcNGetLineInfo, opcNCopyLineInfo, opcNSetLineInfoLine,
opcNSetLineInfoColumn, opcNSetLineInfoFile
opcEqIdent,
opcStrToIdent,
opcGetImpl,

View file

@ -1335,7 +1335,19 @@ proc genMagic(c: PCtx; n: PNode; dest: var TDest; m: TMagic) =
of "copyLineInfo":
internalAssert c.config, n.len == 3
unused(c, n, dest)
genBinaryStmt(c, n, opcNSetLineInfo)
genBinaryStmt(c, n, opcNCopyLineInfo)
of "setLine":
internalAssert c.config, n.len == 3
unused(c, n, dest)
genBinaryStmt(c, n, opcNSetLineInfoLine)
of "setColumn":
internalAssert c.config, n.len == 3
unused(c, n, dest)
genBinaryStmt(c, n, opcNSetLineInfoColumn)
of "setFile":
internalAssert c.config, n.len == 3
unused(c, n, dest)
genBinaryStmt(c, n, opcNSetLineInfoFile)
else: internalAssert c.config, false
of mNHint:
unused(c, n, dest)