condsyms.nim 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. # This module handles the conditional symbols.
  10. import
  11. strtabs, platform, strutils, idents
  12. from options import Feature
  13. from lineinfos import HintsToStr, WarningsToStr
  14. const
  15. catNone = "false"
  16. proc defineSymbol*(symbols: StringTableRef; symbol: string, value: string = "true") =
  17. symbols[symbol] = value
  18. proc undefSymbol*(symbols: StringTableRef; symbol: string) =
  19. symbols[symbol] = catNone
  20. #proc lookupSymbol*(symbols: StringTableRef; symbol: string): string =
  21. # result = if isDefined(symbol): gSymbols[symbol] else: nil
  22. iterator definedSymbolNames*(symbols: StringTableRef): string =
  23. for key, val in pairs(symbols):
  24. if val != catNone: yield key
  25. proc countDefinedSymbols*(symbols: StringTableRef): int =
  26. result = 0
  27. for key, val in pairs(symbols):
  28. if val != catNone: inc(result)
  29. proc initDefines*(symbols: StringTableRef) =
  30. # for bootstrapping purposes and old code:
  31. template defineSymbol(s) = symbols.defineSymbol(s)
  32. defineSymbol("nimhygiene")
  33. defineSymbol("niminheritable")
  34. defineSymbol("nimmixin")
  35. defineSymbol("nimeffects")
  36. defineSymbol("nimbabel")
  37. defineSymbol("nimcomputedgoto")
  38. defineSymbol("nimunion")
  39. defineSymbol("nimnewshared")
  40. defineSymbol("nimNewTypedesc")
  41. defineSymbol("nimrequiresnimframe")
  42. defineSymbol("nimparsebiggestfloatmagic")
  43. defineSymbol("nimalias")
  44. defineSymbol("nimlocks")
  45. defineSymbol("nimnode")
  46. defineSymbol("nimnomagic64")
  47. defineSymbol("nimvarargstyped")
  48. defineSymbol("nimtypedescfixed")
  49. defineSymbol("nimKnowsNimvm")
  50. defineSymbol("nimArrIdx")
  51. defineSymbol("nimHasalignOf")
  52. defineSymbol("nimImmediateDeprecated")
  53. defineSymbol("nimNewShiftOps")
  54. defineSymbol("nimDistros")
  55. defineSymbol("nimHasCppDefine")
  56. defineSymbol("nimGenericInOutFlags")
  57. when false: defineSymbol("nimHasOpt")
  58. defineSymbol("nimNoArrayToCstringConversion")
  59. defineSymbol("nimNewRoof")
  60. defineSymbol("nimHasRunnableExamples")
  61. defineSymbol("nimNewDot")
  62. defineSymbol("nimHasNilChecks")
  63. defineSymbol("nimSymKind")
  64. defineSymbol("nimVmEqIdent")
  65. defineSymbol("nimNoNil")
  66. defineSymbol("nimNoZeroTerminator")
  67. defineSymbol("nimNotNil")
  68. defineSymbol("nimVmExportFixed")
  69. defineSymbol("nimHasSymOwnerInMacro")
  70. defineSymbol("nimNewRuntime")
  71. defineSymbol("nimIncrSeqV3")
  72. defineSymbol("nimAshr")
  73. defineSymbol("nimNoNilSeqs")
  74. defineSymbol("nimNoNilSeqs2")
  75. defineSymbol("nimHasUserErrors")
  76. defineSymbol("nimUncheckedArrayTyp")
  77. defineSymbol("nimHasTypeof")
  78. defineSymbol("nimHasNilSeqs")
  79. for f in low(Feature)..high(Feature):
  80. defineSymbol("nimHas" & $f)
  81. for s in WarningsToStr:
  82. defineSymbol("nimHasWarning" & s)
  83. for s in HintsToStr:
  84. defineSymbol("nimHasHint" & s)