blob: d3b02d74f415aee21684ea0f3245e6f1ac69b4d0 (
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
// $Id$
package scala.tools.selectivecps
import scala.tools.nsc
import nsc.Global
import nsc.plugins.Plugin
import nsc.plugins.PluginComponent
class SelectiveCPSPlugin(val global: Global) extends Plugin {
val name = "continuations"
val description = "applies selective cps conversion"
val anfPhase = new {val global = SelectiveCPSPlugin.this.global } with SelectiveANFTransform() {
val runsAfter = List("pickler")
}
val cpsPhase = new {val global = SelectiveCPSPlugin.this.global } with SelectiveCPSTransform() {
val runsAfter = List("selectiveanf")
override val runsBefore = List("uncurry")
}
val components = List[PluginComponent](anfPhase, cpsPhase)
val checker = new { val global: SelectiveCPSPlugin.this.global.type = SelectiveCPSPlugin.this.global } with CPSAnnotationChecker
global.addAnnotationChecker(checker.checker)
global.analyzer.addAnalyzerPlugin(checker.plugin)
global.log("instantiated cps plugin: " + this)
def setEnabled(flag: Boolean) = {
checker.cpsEnabled = flag
anfPhase.cpsEnabled = flag
cpsPhase.cpsEnabled = flag
}
// TODO: require -enabled command-line flag
override def processOptions(options: List[String], error: String => Unit) = {
var enabled = false
for (option <- options) {
if (option == "enable") {
enabled = true
} else {
error("Option not understood: "+option)
}
}
setEnabled(enabled)
}
override val optionsHelp: Option[String] =
Some(" -P:continuations:enable Enable continuations")
}
|