diff options
author | Paul Phillips <paulp@improving.org> | 2013-05-11 13:02:53 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2013-05-11 13:02:53 -0700 |
commit | 1850ddf380789e364813111282af5ff11e65b52c (patch) | |
tree | 38ae4b5f4f56cf5e24b7ac639b4fb297c171f070 /src/reflect | |
parent | c85a507ba815643faacd8e07270efbd83b700846 (diff) | |
download | scala-1850ddf380789e364813111282af5ff11e65b52c.tar.gz scala-1850ddf380789e364813111282af5ff11e65b52c.tar.bz2 scala-1850ddf380789e364813111282af5ff11e65b52c.zip |
Corralling Modes into a smaller pen.
Attempting to reduce the frequency of low-level operations
with modes. I mean stuff like this:
if ((mode & (EXPRmode | LHSmode)) == EXPRmode)
THey don't make those ten line boolean guards any easier
to understand. Hopefully this will lead us toward eliminating
some of the modes entirely, or at least better isolating
their logic rather than having it interspersed at arbitrary
points throughout the typer.
Modes are in their entirety a leaked implementation detail.
Typing a tree requires a tree and optionally an expected type.
It shouldn't require a bucket of state bits. In subsequent
commits I will start eliminating them.
This commit also breaks adapt down into more digestible chunks.
Diffstat (limited to 'src/reflect')
-rw-r--r-- | src/reflect/scala/reflect/internal/AnnotationInfos.scala | 3 | ||||
-rw-r--r-- | src/reflect/scala/reflect/internal/Mode.scala | 46 | ||||
-rw-r--r-- | src/reflect/scala/reflect/internal/Types.scala | 5 |
3 files changed, 39 insertions, 15 deletions
diff --git a/src/reflect/scala/reflect/internal/AnnotationInfos.scala b/src/reflect/scala/reflect/internal/AnnotationInfos.scala index 90534a9865..73ca74f08e 100644 --- a/src/reflect/scala/reflect/internal/AnnotationInfos.scala +++ b/src/reflect/scala/reflect/internal/AnnotationInfos.scala @@ -40,8 +40,7 @@ trait AnnotationInfos extends api.Annotations { self: SymbolTable => // monomorphic one by introducing existentials, see SI-7009 for details existentialAbstraction(throwableSym.typeParams, throwableSym.tpe) } - val throwsAnn = AnnotationInfo(appliedType(definitions.ThrowsClass, throwableTpe), List(Literal(Constant(throwableTpe))), Nil) - withAnnotations(List(throwsAnn)) + this withAnnotation AnnotationInfo(appliedType(ThrowsClass, throwableTpe), List(Literal(Constant(throwableTpe))), Nil) } /** Tests for, get, or remove an annotation */ diff --git a/src/reflect/scala/reflect/internal/Mode.scala b/src/reflect/scala/reflect/internal/Mode.scala index 516e96cbb3..05fd5c3337 100644 --- a/src/reflect/scala/reflect/internal/Mode.scala +++ b/src/reflect/scala/reflect/internal/Mode.scala @@ -131,20 +131,40 @@ final class Mode private (val bits: Int) extends AnyVal { if (inAny(PATTERNmode | TYPEPATmode)) TYPEmode | TYPEPATmode else TYPEmode - def inAll(required: Mode) = (this & required) == required - def inAny(required: Mode) = (this & required) !=NOmode - def inNone(prohibited: Mode) = (this & prohibited) == NOmode - def inHKMode = inAll(HKmode) - def inFunMode = inAll(FUNmode) - def inPolyMode = inAll(POLYmode) - def inPatternMode = inAll(PATTERNmode) - def inExprMode = inAll(EXPRmode) - def inByValMode = inAll(BYVALmode) - def inRetMode = inAll(RETmode) - - def inPatternNotFunMode = inPatternMode && !inFunMode + def inAll(required: Mode) = (this & required) == required + def inAny(required: Mode) = (this & required) != NOmode + def inNone(prohibited: Mode) = (this & prohibited) == NOmode + def inAllButNone(required: Mode, prohibited: Mode) = inAll(required) && inNone(prohibited) + def in(allOf: Mode = NOmode, noneOf: Mode = NOmode) = inAll(allOf) && inNone(noneOf) + + def inSccMode = inAll(SCCmode) + def inQualMode = inAll(QUALmode) + def inHKMode = inAll(HKmode) + def inFunMode = inAll(FUNmode) + def inPolyMode = inAll(POLYmode) + def inPatternMode = inAll(PATTERNmode) + def inExprMode = inAll(EXPRmode) + def inByValMode = inAll(BYVALmode) + def inRetMode = inAll(RETmode) + def inLhsMode = inAll(LHSmode) + def inTappMode = inAll(TAPPmode) + def inAltMode = inAll(ALTmode) + def inTypeMode = inAll(TYPEmode) + + def typingTypeByValue = inAll(TYPEmode | BYVALmode) + def typingExprByValue = inAll(EXPRmode | BYVALmode) + def typingExprFun = inAll(EXPRmode | FUNmode) + def typingExprNotValue = inAllButNone(EXPRmode, BYVALmode) + def typingExprNotLhs = inAllButNone(EXPRmode, LHSmode) + def typingExprNotFun = inAllButNone(EXPRmode, FUNmode) + def typingExprNotFunNotLhs = inAllButNone(EXPRmode, FUNmode | LHSmode) + def typingMonoExprByValue = inAllButNone(EXPRmode | BYVALmode, POLYmode) + + def typingPatternNotFun = inAllButNone(PATTERNmode, FUNmode) + def typingPatternFun = inAll(PATTERNmode | FUNmode) + def inExprModeOr(others: Mode) = inAny(EXPRmode | others) - def inExprModeButNot(prohibited: Mode) = inAll(EXPRmode) && inNone(prohibited) + def inExprModeButNot(prohibited: Mode) = inAllButNone(EXPRmode, prohibited) override def toString = if (bits == 0) "NOmode" diff --git a/src/reflect/scala/reflect/internal/Types.scala b/src/reflect/scala/reflect/internal/Types.scala index a8fc55e677..338117e188 100644 --- a/src/reflect/scala/reflect/internal/Types.scala +++ b/src/reflect/scala/reflect/internal/Types.scala @@ -3959,6 +3959,11 @@ trait Types case _ => false } + def isExistentialType(tp: Type): Boolean = tp.dealias match { + case ExistentialType(_, _) => true + case _ => false + } + /** This is defined and named as it is because the goal is to exclude source * level types which are not value types (e.g. MethodType) without excluding * necessary internal types such as WildcardType. There are also non-value |