mirror of
https://github.com/waku-org/nwaku.git
synced 2025-01-28 15:46:33 +00:00
28 lines
709 B
Nim
28 lines
709 B
Nim
|
type
|
||
|
SrcLoc* = object
|
||
|
procedure*: cstring
|
||
|
file*: cstring
|
||
|
line*: int
|
||
|
|
||
|
proc `$`*(loc: ptr SrcLoc): string =
|
||
|
result.add loc.file
|
||
|
result.add "("
|
||
|
result.add $loc.line
|
||
|
result.add ")"
|
||
|
result.add " "
|
||
|
if len(loc.procedure) == 0:
|
||
|
result.add "[unspecified]"
|
||
|
else:
|
||
|
result.add loc.procedure
|
||
|
|
||
|
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)
|
||
|
|
||
|
template getSrcLocation*(procedure: static string = ""): ptr SrcLoc =
|
||
|
srcLocImpl(procedure,
|
||
|
instantiationInfo(-2).filename, instantiationInfo(-2).line)
|