effecttraits.nim 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. proc getRaisesListImpl(n: NimNode): NimNode = discard "see compiler/vmops.nim"
  17. proc getTagsListImpl(n: NimNode): NimNode = discard "see compiler/vmops.nim"
  18. proc getForbidsListImpl(n: NimNode): NimNode = discard "see compiler/vmops.nim"
  19. proc isGcSafeImpl(n: NimNode): bool = discard "see compiler/vmops.nim"
  20. proc hasNoSideEffectsImpl(n: NimNode): bool = discard "see compiler/vmops.nim"
  21. proc getRaisesList*(fn: NimNode): NimNode =
  22. ## Extracts the `.raises` list of the func/proc/etc `fn`.
  23. ## `fn` has to be a resolved symbol of kind `nnkSym`. This
  24. ## implies that the macro that calls this proc should accept `typed`
  25. ## arguments and not `untyped` arguments.
  26. expectKind fn, nnkSym
  27. result = getRaisesListImpl(fn)
  28. proc getTagsList*(fn: NimNode): NimNode =
  29. ## Extracts the `.tags` list of the func/proc/etc `fn`.
  30. ## `fn` has to be a resolved symbol of kind `nnkSym`. This
  31. ## implies that the macro that calls this proc should accept `typed`
  32. ## arguments and not `untyped` arguments.
  33. expectKind fn, nnkSym
  34. result = getTagsListImpl(fn)
  35. proc getForbidsList*(fn: NimNode): NimNode =
  36. ## Extracts the `.forbids` list of the func/proc/etc `fn`.
  37. ## `fn` has to be a resolved symbol of kind `nnkSym`. This
  38. ## implies that the macro that calls this proc should accept `typed`
  39. ## arguments and not `untyped` arguments.
  40. expectKind fn, nnkSym
  41. result = getForbidsListImpl(fn)
  42. proc isGcSafe*(fn: NimNode): bool =
  43. ## Return true if the func/proc/etc `fn` is `gcsafe`.
  44. ## `fn` has to be a resolved symbol of kind `nnkSym`. This
  45. ## implies that the macro that calls this proc should accept `typed`
  46. ## arguments and not `untyped` arguments.
  47. expectKind fn, nnkSym
  48. result = isGcSafeImpl(fn)
  49. proc hasNoSideEffects*(fn: NimNode): bool =
  50. ## Return true if the func/proc/etc `fn` has `noSideEffect`.
  51. ## `fn` has to be a resolved symbol of kind `nnkSym`. This
  52. ## implies that the macro that calls this proc should accept `typed`
  53. ## arguments and not `untyped` arguments.
  54. expectKind fn, nnkSym
  55. result = hasNoSideEffectsImpl(fn)