Where does the scala compiler store AST?

The code base of the compiler is quite large, and I can not wrap everything around it all at once :)

Currently, I just want to get AST after the typer phase. Is there any way to do this?

I run the compiler as follows:

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 
+7
source share
2 answers

Use -Xprint:typer (to dump trees after typer) along with -Yshow-trees-compact (to dump trees in raw AST format). If you also use -Yshow-trees-stringified , AST will be further reset as a Scala pseudo-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)))))))) 
+6
source

The code base of the compiler is quite large, and I can not wrap everything around it all at once :)

With the exception of the important typer, most of the phases of the Scala compiler are described in detail in:

http://lampwww.epfl.ch/~magarcia/ScalaCompilerCornerReloaded/

+1
source

All Articles