summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/SubComponent.scala
blob: 625d07bb98a83c0e8b9ac551b1cedafc0c082090 (plain) (blame)
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
/* NSC -- new Scala compiler
 * Copyright 2005-2009 LAMP/EPFL
 * @author Martin Odersky
 */
// $Id$

package scala.tools.nsc

/** 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

  /** 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: Phase = _
  private var ownPhaseRunId = global.NoRunId

  /** The phase corresponding to this subcomponent in the current compiler run */
  def ownPhase: Phase = {
    if (ownPhaseRunId != global.currentRunId) {
      ownPhaseCache = global.currentRun.phaseNamed(phaseName)
      ownPhaseRunId = global.currentRunId
    }
    ownPhaseCache
  }

  /** 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
  }
}