aboutsummaryrefslogtreecommitdiff
path: root/compiler/src/dotty/tools/dotc/core/Mode.scala
diff options
context:
space:
mode:
authorFelix Mulder <felix.mulder@gmail.com>2016-11-02 11:08:28 +0100
committerGuillaume Martres <smarter@ubuntu.com>2016-11-22 01:35:07 +0100
commit8a61ff432543a29234193cd1f7c14abd3f3d31a0 (patch)
treea8147561d307af862c295cfc8100d271063bb0dd /compiler/src/dotty/tools/dotc/core/Mode.scala
parent6a455fe6da5ff9c741d91279a2dc6fe2fb1b472f (diff)
downloaddotty-8a61ff432543a29234193cd1f7c14abd3f3d31a0.tar.gz
dotty-8a61ff432543a29234193cd1f7c14abd3f3d31a0.tar.bz2
dotty-8a61ff432543a29234193cd1f7c14abd3f3d31a0.zip
Move compiler and compiler tests to compiler dir
Diffstat (limited to 'compiler/src/dotty/tools/dotc/core/Mode.scala')
-rw-r--r--compiler/src/dotty/tools/dotc/core/Mode.scala89
1 files changed, 89 insertions, 0 deletions
diff --git a/compiler/src/dotty/tools/dotc/core/Mode.scala b/compiler/src/dotty/tools/dotc/core/Mode.scala
new file mode 100644
index 000000000..406a84af6
--- /dev/null
+++ b/compiler/src/dotty/tools/dotc/core/Mode.scala
@@ -0,0 +1,89 @@
+package dotty.tools.dotc.core
+
+/** A collection of mode bits that are part of a context */
+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 val 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, "InferringReturnType")
+
+ /** This mode bit is set if we collect information without reference to a valid
+ * context with typerstate and constraint. This is typically done when we
+ * cache the eligibility of implicits. Caching needs to be done across different constraints.
+ * Therefore, if TypevarsMissContext is set, subtyping becomes looser, and assumes
+ * that PolyParams can be sub- and supertypes of anything. See TypeComparer.
+ */
+ val TypevarsMissContext = newMode(4, "TypevarsMissContext")
+ val CheckCyclic = newMode(5, "CheckCyclic")
+
+ val InSuperCall = newMode(6, "InSuperCall")
+
+ /** Allow GADTFlexType labelled types to have their bounds adjusted */
+ val GADTflexible = newMode(8, "GADTflexible")
+
+ /** Allow dependent functions. This is currently necessary for unpickling, because
+ * some dependent functions are passed through from the front end(s?), even though they
+ * are technically speaking illegal.
+ */
+ val AllowDependentFunctions = newMode(9, "AllowDependentFunctions")
+
+ /** We are currently printing something: avoid to produce more logs about
+ * the printing
+ */
+ val Printing = newMode(10, "Printing")
+
+ /** We are currently typechecking an ident to determine whether some implicit
+ * is shadowed - don't do any other shadowing tests.
+ */
+ val ImplicitShadowing = newMode(11, "ImplicitShadowing")
+
+ /** We are currently in a `viewExists` check. In that case, ambiguous
+ * implicits checks are disabled and we succeed with the first implicit
+ * found.
+ */
+ val ImplicitExploration = newMode(12, "ImplicitExploration")
+
+ /** We are currently unpickling Scala2 info */
+ val Scala2Unpickling = newMode(13, "Scala2Unpickling")
+
+ /** Use Scala2 scheme for overloading and implicit resolution */
+ val OldOverloadingResolution = newMode(14, "OldOverloadingResolution")
+
+ /** Allow hk applications of type lambdas to wildcard arguments;
+ * used for checking that such applications do not normally arise
+ */
+ val AllowLambdaWildcardApply = newMode(15, "AllowHKApplyToWildcards")
+
+ /** Read original positions when unpickling from TASTY */
+ val ReadPositions = newMode(16, "ReadPositions")
+
+ val PatternOrType = Pattern | Type
+
+ /** We are elaborating the fully qualified name of a package clause.
+ * In this case, identifiers should never be imported.
+ */
+ val InPackageClauseName = newMode(17, "InPackageClauseName")
+}