名前解決とか
2. namer
●
resolve names, attach symbols to named trees
3. packageobjects
4. typer
●
the meat and potatoes: type the trees
5. superaccessors
6. picker
7. refchecks
構文木を探索する
class MyComponent(val global: Global) extends PluginComponent {
…
def newPhase(prev: Phase): Phase = new StdPhase(prev) {
override def apply(unit: CompilationUnit): Unit = {
new ForeachTreeTraverser(onTraverse).traverse(unit.body)
}
}
def onTraverse(tree: Tree): Unit = tree match {
case Apply(fun, args) => println("traversing application of "+ fun)
case _ => ()
}
}
別な構文木に変換する
class MyComponent(val global: Global) extends PluginComponent
with Transform {
def newTransformer(unit: CompilationUnit) = new MyTransformer
class MyTransformer extends Transformer {
override def transform(tree: Tree): Tree = {
postTransform(super.transform(preTransform(tree)))
}
def preTransform(tree: Tree): Tree = tree match {
case _ => tree
}
def postTransform(tree: Tree): Tree = ....
}