-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug_tags.nim
47 lines (43 loc) · 1.3 KB
/
debug_tags.nim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#****h* debug/tags
## PURPOSE
## Scope debug code to specific tags that can be set at compile time.
## EXAMPLE
## ```sh
## nim r -d:debug=tag,othertag,anothertag
## ```
## TODO
## - [ ] support tag exclusion: `nim r -d:debug=-tagname` or maybe `nim r -d:debug=!tagname`
## - [ ] support tag re: `nim r -d:debug=/tag.+/`
#******
import std/[sets, strutils]
#****id* tags/debug const
const debug {.strdefine.}: string = ""
## PURPOSE
## Holds the debug tags that enable debug code.
#******
#****c* tags/debugTags
const debugTags* = (
proc(): HashSet[string] =
if debug.len == 0 or debug == "true":
return ["*"].toHashSet
else:
return debug.split(',').toHashSet
)()
## PURPOSE
## Holds the debug tags that enable debug code.
## DESCRIPTION
## The debug tags are set at compilation like `-d:debug=tag0,tag1,...`.
## The default tag is 'true', which means everything should be enabled.
#******
#****f* tags/allTagsEnabled
proc allTagsEnabled*: bool =
## PURPOSE
## Returns whether all debug tags are enabled.
"*" in debugTags
#******
#****f* tags/inDebugTags
proc inDebugTags*(tags: seq[string]): bool =
## PURPOSE
## Tests whether any tag in a set is contained in the set of debug tags.
allTagsEnabled() or not disjoint(tags.toHashSet, debugTags)
#******