diff options
3 files changed, 39 insertions, 30 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/patmat/MatchCps.scala b/src/compiler/scala/tools/nsc/transform/patmat/MatchCps.scala new file mode 100644 index 0000000000..0d08120e43 --- /dev/null +++ b/src/compiler/scala/tools/nsc/transform/patmat/MatchCps.scala @@ -0,0 +1,37 @@ +/* NSC -- new Scala compiler + * + * Copyright 2011-2013 LAMP/EPFL + * @author Adriaan Moors + */ + +package scala.tools.nsc.transform.patmat + +/** Segregating this super hacky CPS code. */ +trait MatchCps { + self: PatternMatching => + + import global._ + + // duplicated from CPSUtils (avoid dependency from compiler -> cps plugin...) + private object CpsSymbols { + private def cpsSymbol(name: String) = rootMirror.getClassIfDefined(s"scala.util.continuations.$name") + + val MarkerCPSAdaptPlus = cpsSymbol("cpsPlus") + val MarkerCPSAdaptMinus = cpsSymbol("cpsMinus") + val MarkerCPSSynth = cpsSymbol("cpsSynth") + val MarkerCPSTypes = cpsSymbol("cpsParam") + val stripTriggerCPSAnns = Set[Symbol](MarkerCPSSynth, MarkerCPSAdaptMinus, MarkerCPSAdaptPlus) + val strippedCPSAnns = stripTriggerCPSAnns + MarkerCPSTypes + + // when one of the internal cps-type-state annotations is present, strip all CPS annotations + // a cps-type-state-annotated type makes no sense as an expected type (matchX.tpe is used as pt in translateMatch) + // (only test availability of MarkerCPSAdaptPlus assuming they are either all available or none of them are) + def removeCPSFromPt(pt: Type): Type = ( + if (MarkerCPSAdaptPlus.exists && (stripTriggerCPSAnns exists pt.hasAnnotation)) + pt filterAnnotations (ann => !(strippedCPSAnns exists ann.matches)) + else + pt + ) + } + def removeCPSFromPt(pt: Type): Type = CpsSymbols removeCPSFromPt pt +} diff --git a/src/compiler/scala/tools/nsc/transform/patmat/MatchTranslation.scala b/src/compiler/scala/tools/nsc/transform/patmat/MatchTranslation.scala index a91f24ef0e..282a78492a 100644 --- a/src/compiler/scala/tools/nsc/transform/patmat/MatchTranslation.scala +++ b/src/compiler/scala/tools/nsc/transform/patmat/MatchTranslation.scala @@ -10,38 +10,9 @@ import scala.language.postfixOps import scala.collection.mutable import scala.reflect.internal.util.Statistics - -/** Segregating this super hacky code. */ -trait CpsPatternHacks { - self: PatternMatching => - - import global._ - - // duplicated from CPSUtils (avoid dependency from compiler -> cps plugin...) - private object CpsSymbols { - val MarkerCPSAdaptPlus = rootMirror.getClassIfDefined("scala.util.continuations.cpsPlus") - val MarkerCPSAdaptMinus = rootMirror.getClassIfDefined("scala.util.continuations.cpsMinus") - val MarkerCPSSynth = rootMirror.getClassIfDefined("scala.util.continuations.cpsSynth") - val MarkerCPSTypes = rootMirror.getClassIfDefined("scala.util.continuations.cpsParam") - val stripTriggerCPSAnns = Set[Symbol](MarkerCPSSynth, MarkerCPSAdaptMinus, MarkerCPSAdaptPlus) - val strippedCPSAnns = stripTriggerCPSAnns + MarkerCPSTypes - - // when one of the internal cps-type-state annotations is present, strip all CPS annotations - // a cps-type-state-annotated type makes no sense as an expected type (matchX.tpe is used as pt in translateMatch) - // (only test availability of MarkerCPSAdaptPlus assuming they are either all available or none of them are) - def removeCPSFromPt(pt: Type): Type = ( - if (MarkerCPSAdaptPlus.exists && (stripTriggerCPSAnns exists pt.hasAnnotation)) - pt filterAnnotations (ann => !(strippedCPSAnns exists ann.matches)) - else - pt - ) - } - def removeCPSFromPt(pt: Type): Type = CpsSymbols removeCPSFromPt pt -} - /** Translate typed Trees that represent pattern matches into the patternmatching IR, defined by TreeMakers. */ -trait MatchTranslation extends CpsPatternHacks { +trait MatchTranslation { self: PatternMatching => import PatternMatchingStats._ diff --git a/src/compiler/scala/tools/nsc/transform/patmat/PatternMatching.scala b/src/compiler/scala/tools/nsc/transform/patmat/PatternMatching.scala index f3514b2d06..21666ed0ec 100644 --- a/src/compiler/scala/tools/nsc/transform/patmat/PatternMatching.scala +++ b/src/compiler/scala/tools/nsc/transform/patmat/PatternMatching.scala @@ -40,6 +40,7 @@ trait PatternMatching extends Transform with TypingTransformers with MatchTranslation with MatchTreeMaking with MatchCodeGen + with MatchCps with ScalaLogic with Solving with MatchAnalysis |