package scala.tools.nsc
package typechecker
trait Modes {
final val NOmode = 0x000
final val EXPRmode = 0x001
final val PATTERNmode = 0x002
final val TYPEmode = 0x004
final val SCCmode = 0x008
final val FUNmode = 0x010
final val POLYmode = 0x020
final val QUALmode = 0x040
final val TAPPmode = 0x080
final val SUPERCONSTRmode = 0x100
final val SNDTRYmode = 0x200
final val LHSmode = 0x400
final val STARmode = 0x1000
final val ALTmode = 0x2000
final val HKmode = 0x4000
final val BYVALmode = 0x8000
final val TYPEPATmode = 0x10000
final private val StickyModes = EXPRmode | PATTERNmode | TYPEmode | ALTmode
final def onlyStickyModes(mode: Int) =
mode & StickyModes
final def forFunMode(mode: Int) =
mode & (StickyModes | SCCmode) | FUNmode | POLYmode | BYVALmode
final def forTypeMode(mode: Int) =
if (inAnyMode(mode, PATTERNmode | TYPEPATmode)) TYPEmode | TYPEPATmode
else TYPEmode
final def inAllModes(mode: Int, required: Int) = (mode & required) == required
final def inAnyMode(mode: Int, required: Int) = (mode & required) != 0
final def inNoModes(mode: Int, prohibited: Int) = (mode & prohibited) == 0
final def inHKMode(mode: Int) = (mode & HKmode) != 0
final def inFunMode(mode: Int) = (mode & FUNmode) != 0
final def inPolyMode(mode: Int) = (mode & POLYmode) != 0
final def inPatternMode(mode: Int) = (mode & PATTERNmode) != 0
private val modeNameMap = Map[Int, String](
(1 << 0) -> "EXPRmode",
(1 << 1) -> "PATTERNmode",
(1 << 2) -> "TYPEmode",
(1 << 3) -> "SCCmode",
(1 << 4) -> "FUNmode",
(1 << 5) -> "POLYmode",
(1 << 6) -> "QUALmode",
(1 << 7) -> "TAPPmode",
(1 << 8) -> "SUPERCONSTRmode",
(1 << 9) -> "SNDTRYmode",
(1 << 10) -> "LHSmode",
(1 << 11) -> "<DOES NOT EXIST mode>",
(1 << 12) -> "STARmode",
(1 << 13) -> "ALTmode",
(1 << 14) -> "HKmode",
(1 << 15) -> "BYVALmode",
(1 << 16) -> "TYPEPATmode"
)
def modeString(mode: Int): String =
if (mode == 0) "NOmode"
else (modeNameMap filterKeys (bit => inAllModes(mode, bit))).values mkString " "
}