Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 76 lines (57 sloc) 2.381 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
/* NSC -- new Scala compiler
* Copyright 2005-2013 LAMP/EPFL
* @author Martin Odersky
*/

package scala.tools.nsc

import scala.ref.WeakReference

/** An nsc sub-component.
*
* @author Martin Odersky
*/
abstract class SubComponent {

  /** The global environment; overridden by instantiation in Global. */
  val global: Global

  /** The name of the phase */
  val phaseName: String

  /** List of phase names, this phase should run after */
  val runsAfter: List[String]

  /** List of phase names, this phase should run before */
  val runsBefore: List[String] = Nil

  /** Phase name this phase will attach itself to, not allowing any phase to come between it
* and the phase name declared */
  val runsRightAfter: Option[String]

  /** Internal flag to tell external from internal phases */
  val internal: Boolean = true

  /** SubComponent are added to a HashSet and two phases are the same if they have the same name */
  override def hashCode() = phaseName.hashCode()

  /** New flags defined by the phase which are not valid before */
  def phaseNewFlags: Long = 0

  /** New flags defined by the phase which are not valid until immediately after it */
  def phaseNextFlags: Long = 0

  /** The phase factory */
  def newPhase(prev: Phase): Phase

  private var ownPhaseCache: WeakReference[Phase] = new WeakReference(null)
  private var ownPhaseRunId = global.NoRunId

  @inline final def beforeOwnPhase[T](op: => T) = global.enteringPhase(ownPhase)(op)
  @inline final def afterOwnPhase[T](op: => T) = global.exitingPhase(ownPhase)(op)

  /** The phase corresponding to this subcomponent in the current compiler run */
  def ownPhase: Phase = {
    ownPhaseCache.get match {
      case Some(phase) if ownPhaseRunId == global.currentRunId =>
        phase
      case _ =>
        val phase = global.currentRun.phaseNamed(phaseName)
        ownPhaseCache = new WeakReference(phase)
        ownPhaseRunId = global.currentRunId
        phase
    }
  }

  /** The phase defined by this subcomponent. Can be called only after phase is installed by newPhase. */
  // lazy val ownPhase: Phase = global.currentRun.phaseNamed(phaseName)

  /** A standard phase template */
  abstract class StdPhase(prev: Phase) extends global.GlobalPhase(prev) {
    def name = phaseName
    override def newFlags = phaseNewFlags
    override def nextFlags = phaseNextFlags
  }
}
Something went wrong with that request. Please try again.