pluginsupport.nim 943 B

12345678910111213141516171819202122232425262728293031323334
  1. #
  2. #
  3. # The Nim Compiler
  4. # (c) Copyright 2015 Andreas Rumpf
  5. #
  6. # See the file "copying.txt", included in this
  7. # distribution, for details about the copyright.
  8. #
  9. ## Plugin support for the Nim compiler. Right now plugins
  10. ## need to be built with the compiler only: plugins using
  11. ## DLLs or the FFI will not work.
  12. import ast, semdata, idents
  13. type
  14. Transformation* = proc (c: PContext; n: PNode): PNode {.nimcall.}
  15. Plugin* = tuple
  16. package, module, fn: string
  17. t: Transformation
  18. proc pluginMatches*(ic: IdentCache; p: Plugin; s: PSym): bool =
  19. if s.name.id != ic.getIdent(p.fn).id:
  20. return false
  21. let module = s.skipGenericOwner
  22. if module == nil or module.kind != skModule or
  23. module.name.id != ic.getIdent(p.module).id:
  24. return false
  25. let package = module.owner
  26. if package == nil or package.kind != skPackage or
  27. package.name.id != ic.getIdent(p.package).id:
  28. return false
  29. return true