Permalink
Browse files

de-duplicate isUncheckedAnnotation/isSwitchAnnotation

  • Loading branch information...
adriaanm authored and xeno-by committed Jun 5, 2012
1 parent b31c6d4 commit 10292e4acbb8eb0143a5a087c750ed9699f31807
@@ -410,18 +410,15 @@ abstract class ExplicitOuter extends InfoTransform
(CASE(transform(strippedPat)) IF gdcall) ==> transform(body)
}
- def isUncheckedAnnotation(tpe: Type) = tpe hasAnnotation UncheckedClass
- def isSwitchAnnotation(tpe: Type) = tpe hasAnnotation SwitchClass
-
val (checkExhaustive, requireSwitch) = nselector match {
case Typed(nselector1, tpt) =>
- val unchecked = isUncheckedAnnotation(tpt.tpe)
+ val unchecked = treeInfo.isUncheckedAnnotation(tpt.tpe)
if (unchecked)
nselector = nselector1
// Don't require a tableswitch if there are 1-2 casedefs
// since the matcher intentionally emits an if-then-else.
- (!unchecked, isSwitchAnnotation(tpt.tpe) && ncases.size > 2)
+ (!unchecked, treeInfo.isSwitchAnnotation(tpt.tpe) && ncases.size > 2)
case _ =>
(true, false)
}
@@ -1110,16 +1110,13 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
def matchFailGen = (matchFailGenOverride orElse Some(CODE.MATCHERROR(_: Tree)))
// patmatDebug("combining cases: "+ (casesNoSubstOnly.map(_.mkString(" >> ")).mkString("{", "\n", "}")))
- def isSwitchAnnotation(tpe: Type) = tpe hasAnnotation SwitchClass
- def isUncheckedAnnotation(tpe: Type) = tpe hasAnnotation UncheckedClass
-
val (unchecked, requireSwitch) =
if (settings.XnoPatmatAnalysis.value) (true, false)
else scrut match {
case Typed(_, tpt) =>
- (isUncheckedAnnotation(tpt.tpe),
+ (treeInfo.isUncheckedAnnotation(tpt.tpe),
// matches with two or fewer cases need not apply for switchiness (if-then-else will do)
- isSwitchAnnotation(tpt.tpe) && casesNoSubstOnly.lengthCompare(2) > 0)
+ treeInfo.isSwitchAnnotation(tpt.tpe) && casesNoSubstOnly.lengthCompare(2) > 0)
case _ =>
(false, false)
}
@@ -326,6 +326,12 @@ abstract class TreeInfo {
case _ => false
}
+ /** a Match(Typed(_, tpt), _) is unchecked if isUncheckedAnnotation(tpt.tpe) */
+ def isUncheckedAnnotation(tpe: Type) = tpe hasAnnotation definitions.UncheckedClass
+
+ /** a Match(Typed(_, tpt), _) must be translated into a switch if isSwitchAnnotation(tpt.tpe) */
+ def isSwitchAnnotation(tpe: Type) = tpe hasAnnotation definitions.SwitchClass
+
/** can this type be a type pattern */
def mayBeTypePat(tree: Tree): Boolean = tree match {
case CompoundTypeTree(Template(tps, _, Nil)) => tps exists mayBeTypePat

0 comments on commit 10292e4

Please sign in to comment.