m18235.nim 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import macros
  2. # Necessary code to update the AST on a symbol across module boundaries when
  3. # processed by a type macro. Used by a test of a corresponding name of this
  4. # file.
  5. macro eexport(n: typed): untyped =
  6. result = copyNimTree(n)
  7. # turn exported nnkSym -> nnkPostfix(*, nnkIdent), forcing re-sem
  8. result[0] = nnkPostfix.newTree(ident"*").add:
  9. n.name.strVal.ident
  10. macro unexport(n: typed): untyped =
  11. result = copyNimTree(n)
  12. # turn nnkSym -> nnkIdent, forcing re-sem and dropping any exported-ness
  13. # that might be present
  14. result[0] = n.name.strVal.ident
  15. proc foo*() {.unexport.} = discard
  16. proc bar() {.eexport.} = discard
  17. proc foooof*() {.unexport, eexport, unexport.} = discard
  18. proc barrab() {.eexport, unexport, eexport.} = discard
  19. macro eexportMulti(n: typed): untyped =
  20. # use the call version of `eexport` macro for one or more decls
  21. result = copyNimTree(n)
  22. for i in 0..<result.len:
  23. result[i] = newCall(ident"eexport", result[i])
  24. macro unexportMulti(n: typed): untyped =
  25. # use the call version of `unexport` macro for one or more decls
  26. result = copyNimTree(n)
  27. for i in 0..<result.len:
  28. result[i] = newCall(ident"unexport", result[i])
  29. unexportMulti:
  30. proc oof*() = discard
  31. eexportMulti:
  32. proc rab() = discard
  33. proc baz*() = discard