effecttraits.nim 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #
  2. #
  3. # Nim's Runtime Library
  4. # (c) Copyright 2020 Nim contributors
  5. #
  6. # See the file "copying.txt", included in this
  7. # distribution, for details about the copyright.
  8. #
  9. ## This module provides access to the inferred .raises effects
  10. ## for Nim's macro system.
  11. ## **Since**: Version 1.4.
  12. ##
  13. ## One can test for the existence of this standard module
  14. ## via `defined(nimHasEffectTraitsModule)`.
  15. import std/macros
  16. when defined(nimPreviewSlimSystem):
  17. import std/assertions
  18. proc getRaisesListImpl(n: NimNode): NimNode = raiseAssert "see compiler/vmops.nim"
  19. proc getTagsListImpl(n: NimNode): NimNode = raiseAssert "see compiler/vmops.nim"
  20. proc getForbidsListImpl(n: NimNode): NimNode = raiseAssert "see compiler/vmops.nim"
  21. proc isGcSafeImpl(n: NimNode): bool = raiseAssert "see compiler/vmops.nim"
  22. proc hasNoSideEffectsImpl(n: NimNode): bool = raiseAssert "see compiler/vmops.nim"
  23. proc getRaisesList*(fn: NimNode): NimNode =
  24. ## Extracts the `.raises` list of the func/proc/etc `fn`.
  25. ## `fn` has to be a resolved symbol of kind `nnkSym`. This
  26. ## implies that the macro that calls this proc should accept `typed`
  27. ## arguments and not `untyped` arguments.
  28. expectKind fn, nnkSym
  29. result = getRaisesListImpl(fn)
  30. proc getTagsList*(fn: NimNode): NimNode =
  31. ## Extracts the `.tags` list of the func/proc/etc `fn`.
  32. ## `fn` has to be a resolved symbol of kind `nnkSym`. This
  33. ## implies that the macro that calls this proc should accept `typed`
  34. ## arguments and not `untyped` arguments.
  35. expectKind fn, nnkSym
  36. result = getTagsListImpl(fn)
  37. proc getForbidsList*(fn: NimNode): NimNode =
  38. ## Extracts the `.forbids` list of the func/proc/etc `fn`.
  39. ## `fn` has to be a resolved symbol of kind `nnkSym`. This
  40. ## implies that the macro that calls this proc should accept `typed`
  41. ## arguments and not `untyped` arguments.
  42. expectKind fn, nnkSym
  43. result = getForbidsListImpl(fn)
  44. proc isGcSafe*(fn: NimNode): bool =
  45. ## Return true if the func/proc/etc `fn` is `gcsafe`.
  46. ## `fn` has to be a resolved symbol of kind `nnkSym`. This
  47. ## implies that the macro that calls this proc should accept `typed`
  48. ## arguments and not `untyped` arguments.
  49. expectKind fn, nnkSym
  50. result = isGcSafeImpl(fn)
  51. proc hasNoSideEffects*(fn: NimNode): bool =
  52. ## Return true if the func/proc/etc `fn` has `noSideEffect`.
  53. ## `fn` has to be a resolved symbol of kind `nnkSym`. This
  54. ## implies that the macro that calls this proc should accept `typed`
  55. ## arguments and not `untyped` arguments.
  56. expectKind fn, nnkSym
  57. result = hasNoSideEffectsImpl(fn)