nim-chronos/chronos/srcloc.nim

28 lines
709 B
Nim
Raw Normal View History

type
SrcLoc* = object
2019-04-08 13:46:22 +00:00
procedure*: cstring
file*: cstring
line*: int
proc `$`*(loc: ptr SrcLoc): string =
result.add loc.file
2019-04-08 13:46:22 +00:00
result.add "("
result.add $loc.line
2019-04-08 13:46:22 +00:00
result.add ")"
result.add " "
if len(loc.procedure) == 0:
result.add "[unspecified]"
else:
result.add loc.procedure
2019-04-08 13:46:22 +00:00
proc srcLocImpl(procedure: static string,
file: static string, line: static int): ptr SrcLoc =
var loc {.global.} = SrcLoc(
file: cstring(file), line: line, procedure: procedure
)
return addr(loc)
2019-04-08 13:46:22 +00:00
template getSrcLocation*(procedure: static string = ""): ptr SrcLoc =
srcLocImpl(procedure,
instantiationInfo(-2).filename, instantiationInfo(-2).line)