summaryrefslogtreecommitdiff
path: root/src/compiler/scala/reflect/makro/runtime/Settings.scala
blob: 32f7115db890de24a0069e88cf06856535479728 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package scala.reflect.makro
package runtime

trait Settings {
  self: Context =>

  def settings: List[String] = {
    val optionName = mirror.settings.XmacroSettings.name
    val settings = compilerSettings.find(opt => opt.startsWith(optionName)).map(opt => opt.substring(optionName.length + 1)).getOrElse("")
    settings.split(",").toList
  }

  def compilerSettings: List[String] = mirror.settings.recreateArgs

  def setCompilerSettings(options: String): this.type =
    // todo. is not going to work with quoted arguments with embedded whitespaces
    setCompilerSettings(options.split(" ").toList)

  def setCompilerSettings(options: List[String]): this.type = {
    val settings = new tools.nsc.Settings(_ => ())
    // [Eugene] what settings should we exclude?
    settings.copyInto(mirror.settings)
    this
  }

  def withCompilerSettings[T](options: String)(op: => T): T =
    // todo. is not going to work with quoted arguments with embedded whitespaces
    withCompilerSettings(options.split(" ").toList)(op)

  def withCompilerSettings[T](options: List[String])(op: => T): T = {
    val old = options
    setCompilerSettings(options)
    try op
    finally setCompilerSettings(old)
  }
}