aboutsummaryrefslogblamecommitdiff
path: root/src/dotty/tools/dotc/typer/Mode.scala
blob: 65afbd7c8eca325e02291c9844aea7b99e504ecc (plain) (tree)
1
2
3
4
5
6
7
8
9
10

                              

                         
                                               
               



                                                       




                                                                                              


             


                                              
 



                                               
 

                                     
 
                                                       
                                                               
 

                                                             
                                    
 
package dotty.tools.dotc.typer

import collection.mutable

case class Mode(val bits: Int) extends AnyVal {
  import Mode._
  def | (that: Mode) = Mode(bits | that.bits)
  def & (that: Mode) = Mode(bits & that.bits)
  def &~ (that: Mode) = Mode(bits & ~that.bits)
  def is (that: Mode) = (bits & that.bits) == that.bits

  def isExpr = (this & PatternOrType) == None

  override def toString =
    (0 until 31).filter(i => (bits & (1 << i)) != 0).map(modeName).mkString("Mode(", ",", ")")
}

object Mode {
  val None = Mode(0)

  private var modeName = new Array[String](32)

  def newMode(bit: Int, name: String): Mode = {
    modeName(bit) = name
    Mode(1 << bit)
  }

  val Pattern = newMode(0, "Pattern")
  val Type = newMode(1, "Type")

  val ImplicitsEnabled = newMode(2, "ImplicitsEnabled")
  val InferringReturnType = newMode(3, "InferencingReturnType")

  val TypevarsMissContext = newMode(4, "TypevarsMissContext")

  val PatternOrType = Pattern | Type
}