backendpragmas.nim 930 B

1234567891011121314151617181920212223242526
  1. import pragmas, options, ast, trees
  2. proc pushBackendOption(optionsStack: var seq[TOptions], options: var TOptions) =
  3. optionsStack.add options
  4. proc popBackendOption(optionsStack: var seq[TOptions], options: var TOptions) =
  5. options = optionsStack[^1]
  6. optionsStack.setLen(optionsStack.len-1)
  7. proc processPushBackendOption*(optionsStack: var seq[TOptions], options: var TOptions,
  8. n: PNode, start: int) =
  9. pushBackendOption(optionsStack, options)
  10. for i in start..<n.len:
  11. let it = n[i]
  12. if it.kind in nkPragmaCallKinds and it.len == 2 and it[1].kind == nkIntLit:
  13. let sw = whichPragma(it[0])
  14. let opts = pragmaToOptions(sw)
  15. if opts != {}:
  16. if it[1].intVal != 0:
  17. options.incl opts
  18. else:
  19. options.excl opts
  20. template processPopBackendOption*(optionsStack: var seq[TOptions], options: var TOptions) =
  21. popBackendOption(optionsStack, options)