scala编译器在哪里存储AST?

Rog*_*ach 7 scala

编译器代码库非常大,我无法立刻解决所有问题:)

目前,我只想在"typer"阶段之后获得AST.有办法吗?

我按以下方式运行编译器:

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
Run Code Online (Sandbox Code Playgroud)

Eug*_*ako 6

使用-Xprint:typer(在typer之后转储树)和-Yshow-trees-compact(以原始AST格式转储树).如果你也使用-Yshow-trees-stringified,ASTs将被另外转储为伪Scala代码(注意:最后两个选项需要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))))))))
Run Code Online (Sandbox Code Playgroud)