Guillaume Martres - EPFL
obj.fun(5)
obj.fun(5)
Apply(Select(Ident("obj"), "fun"), Literal(5))
class A {
def fun(x: Int): Int = x
}
val obj: A = new A
obj.fun(5)
class A[T] { def fun(x: T): T = x } val obj: A[Int] = new A[Int] obj.fun(5)
class TermRef(prefix: Type, name: String) extends Type
override def transform(tree: Tree): Tree = {
// call "transform" on every node that tree points to
val tree1 = transformChildren(tree)
tree1 match {
case tree: Apply =>
// make a new tree and return it
...
case tree: Select =>
// make a new tree and return it
...
case tree => // default case
tree1
}
}
// Precondition of each transformX method: children nodes
// are already transformed by this phase
override def transformApply(tree: Apply): Tree = {
// make a new tree and return it
...
}
override def transformSelect(tree: Select): Tree = {
// make a new tree and return it
...
}
// No need to override transformX if we do not need to
// transform them
Let's implement a simple phase to trace method calls at runtime. The final code is at
https://github.com/smarter/dotty/commits/live-demo