2019-04-08 00:59:49 +00:00
|
|
|
type
|
|
|
|
SrcLoc* = object
|
2019-04-08 13:46:22 +00:00
|
|
|
procedure*: cstring
|
2019-04-08 00:59:49 +00:00
|
|
|
file*: cstring
|
|
|
|
line*: int
|
|
|
|
|
|
|
|
proc `$`*(loc: ptr SrcLoc): string =
|
|
|
|
result.add loc.file
|
2019-04-08 13:46:22 +00:00
|
|
|
result.add "("
|
2019-04-08 00:59:49 +00:00
|
|
|
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 00:59:49 +00:00
|
|
|
|
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
|
|
|
|
)
|
2019-04-08 00:59:49 +00:00
|
|
|
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)
|