Compiler codebase is quite big, and I can't wrap my head around it all at once :)
Currently, I just want to get ASTs after "typer" phase from it. Is there a way to do it?
I run the compiler the following way:
val settings = new Settings
settings.classpath.value = ...
val compiler = new Global(settings, new ConsoleReporter(settings))
new compiler.Run() {
override def stopPhase(name: String) = name == "superaccessors"
} compileSources files
Use -Xprint:typer
(to dump trees after typer) together with -Yshow-trees-compact
(to dump the trees in raw AST format). If you also use -Yshow-trees-stringified
, ASTs will be additionally dumped as pseudo Scala code (note: the last two options require 2.10.0).
C:\Projects\Kepler\sandbox @ ticket/6356>cat Test.scala
class C {
def x = 2
}
C:\Projects\Kepler\sandbox @ ticket/6356>scalac -Xprint:typer -Yshow-trees-compact -Yshow-trees-stringified Test.scala
[[syntax trees at end of typer]]// Scala source: Test.scala
package <empty> {
class C extends scala.AnyRef {
def <init>(): C = {
C.super.<init>();
()
};
def x: Int = 2
}
}
PackageDef(
Ident(<empty>),
List(
ClassDef(Modifiers(), newTypeName("C"), List(),
Template(List(Select(Ident(scala), newTypeName("AnyRef"))), emptyValDef,
List(
DefDef(Modifiers(), nme.CONSTRUCTOR, List(), List(List()), TypeTree(), Block(List(Apply(Select(Super(This(newTypeName("C")), tpnme.EMPTY), nme.CONSTRUCTOR), List())), Literal(Constant(())))),
DefDef(Modifiers(), newTermName("x"), List(), List(), TypeTree(), Literal(Constant(2))))))))
Compiler codebase is quite big, and I can't wrap my head around it all at once :)
Except for the all important typer, most phases of the Scala compiler are described in detail at:
http://lampwww.epfl.ch/~magarcia/ScalaCompilerCornerReloaded/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With