summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2013-05-11 13:02:54 -0700
committerPaul Phillips <paulp@improving.org>2013-05-11 13:02:54 -0700
commit433880e91cba9e1e926e9fcbf04ecd4aeb1d73eb (patch)
treecc12050e025e2fe0b38fa1cea9e9d64d784f5131 /src/compiler/scala/tools/nsc/typechecker/Contexts.scala
parent24cad039b309cf3ccd79aca8f3bae398a42ab66b (diff)
downloadscala-433880e91cba9e1e926e9fcbf04ecd4aeb1d73eb.tar.gz
scala-433880e91cba9e1e926e9fcbf04ecd4aeb1d73eb.tar.bz2
scala-433880e91cba9e1e926e9fcbf04ecd4aeb1d73eb.zip
Refactored stabilize.
Mode elimination ramps up in difficulty now, so I pursued other forms of code hygiene.
Diffstat (limited to 'src/compiler/scala/tools/nsc/typechecker/Contexts.scala')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Contexts.scala43
1 files changed, 31 insertions, 12 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
index e0b7f8b670..fc1db32a2d 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
@@ -356,21 +356,33 @@ trait Contexts { self: Analyzer =>
finally contextMode = saved
}
- def withImplicitsEnabled[T](op: => T): T = withMode(enabled = ImplicitsEnabled)(op)
- def withImplicitsDisabled[T](op: => T): T = withMode(disabled = ImplicitsEnabled | EnrichmentEnabled)(op)
- def withImplicitsDisabledAllowEnrichment[T](op: => T): T = withMode(enabled = EnrichmentEnabled, disabled = ImplicitsEnabled)(op)
- def withMacrosEnabled[T](op: => T): T = withMode(enabled = MacrosEnabled)(op)
- def withMacrosDisabled[T](op: => T): T = withMode(disabled = MacrosEnabled)(op)
- def withStarPatterns[T](op: => T): T = withMode(enabled = StarPatterns)(op)
- def withSuperInit[T](op: => T): T = withMode(enabled = SuperInit)(op)
- def withSecondTry[T](op: => T): T = withMode(enabled = SecondTry)(op)
- def withTypeConstructor[T](op: => T): T = withMode(enabled = TypeConstructor)(op)
-
- def withReturnExpr[T](op: => T): T = {
+ @inline final def withImplicitsEnabled[T](op: => T): T = withMode(enabled = ImplicitsEnabled)(op)
+ @inline final def withImplicitsDisabled[T](op: => T): T = withMode(disabled = ImplicitsEnabled | EnrichmentEnabled)(op)
+ @inline final def withImplicitsDisabledAllowEnrichment[T](op: => T): T = withMode(enabled = EnrichmentEnabled, disabled = ImplicitsEnabled)(op)
+ @inline final def withMacrosEnabled[T](op: => T): T = withMode(enabled = MacrosEnabled)(op)
+ @inline final def withMacrosDisabled[T](op: => T): T = withMode(disabled = MacrosEnabled)(op)
+ @inline final def withinStarPatterns[T](op: => T): T = withMode(enabled = StarPatterns)(op)
+ @inline final def withinSuperInit[T](op: => T): T = withMode(enabled = SuperInit)(op)
+ @inline final def withinSecondTry[T](op: => T): T = withMode(enabled = SecondTry)(op)
+ @inline final def withinTypeConstructor[T](op: => T): T = withMode(enabled = TypeConstructor)(op)
+
+ /* TODO - consolidate returnsSeen (which seems only to be used by checkDead)
+ * and ReturnExpr.
+ */
+ @inline final def withinReturnExpr[T](op: => T): T = {
enclMethod.returnsSeen = true
withMode(enabled = ReturnExpr)(op)
}
+ /** TODO: The "sticky modes" are EXPRmode, PATTERNmode, TYPEmode.
+ * To mimick the sticky mode behavior, when captain stickyfingers
+ * comes around we need to propagate those modes but forget the other
+ * context modes which were once mode bits; those being so far the
+ * ones listed here.
+ */
+ @inline final def withOnlyStickyModes[T](op: => T): T =
+ withMode(disabled = PatternAlternative | StarPatterns | SuperInit | SecondTry | ReturnExpr | TypeConstructor | TypeApplication)(op)
+
/** @return true if the `expr` evaluates to true within a silent Context that incurs no errors */
@inline final def inSilentMode(expr: => Boolean): Boolean = {
withMode() { // withMode with no arguments to restore the mode mutated by `setBufferErrors`.
@@ -1371,6 +1383,12 @@ object ContextMode {
/** Are we typing a type constructor? Formerly HKmode. */
final val TypeConstructor: ContextMode = 1 << 16
+ /** Are we in the function/type constructor part of a type application?
+ * When we are, we do not decompose PolyTypes. Formerly TAPPmode.
+ * TODO.
+ */
+ final val TypeApplication: ContextMode = 1 << 17
+
final val DefaultMode: ContextMode = MacrosEnabled
private val contextModeNameMap = Map(
@@ -1387,7 +1405,8 @@ object ContextMode {
StarPatterns -> "StarPatterns",
SuperInit -> "SuperInit",
SecondTry -> "SecondTry",
- TypeConstructor -> "TypeConstructor"
+ TypeConstructor -> "TypeConstructor",
+ TypeApplication -> "TypeApplication"
)
}