typingtransformers.scala

来自「JAVA 语言的函数式编程扩展」· SCALA 代码 · 共 52 行

SCALA
52
字号
/* NSC -- new Scala compiler * Copyright 2005-2008 LAMP/EPFL * @author Martin Odersky */// $Id: TypingTransformers.scala 13738 2008-01-18 19:53:56Z michelou $package scala.tools.nsc.transformimport scala.collection.mutable.{Map, HashMap}/** A base class for transforms. *  A transform contains a compiler phase which applies a tree transformer. */trait TypingTransformers {  val global: Global  import global._  abstract class TypingTransformer(unit: CompilationUnit) extends Transformer {    var localTyper: analyzer.Typer = analyzer.newTyper(      analyzer.rootContext(unit, EmptyTree, true))    protected var curTree: Tree = _    /** a typer for each enclosing class */    var typers: Map[Symbol, analyzer.Typer] = new HashMap        override def atOwner[A](owner: Symbol)(trans: => A): A = atOwner(curTree, owner)(trans)    def atOwner[A](tree: Tree, owner: Symbol)(trans: => A): A = {      val savedLocalTyper = localTyper      localTyper = localTyper.atOwner(tree, owner)      typers += Pair(owner, localTyper)      val result = super.atOwner(owner)(trans)      localTyper = savedLocalTyper      typers -= owner      result    }    override def transform(tree: Tree): Tree = {      curTree = tree      tree match {        case Template(_, _, _) =>          // enter template into context chain          atOwner(currentOwner) { super.transform(tree) }        case _ =>          super.transform(tree)      }    }  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?