diff options
Diffstat (limited to 'src/continuations')
-rw-r--r-- | src/continuations/plugin/scala/tools/selectivecps/CPSAnnotationChecker.scala | 31 | ||||
-rw-r--r-- | src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSPlugin.scala | 1 |
2 files changed, 20 insertions, 12 deletions
diff --git a/src/continuations/plugin/scala/tools/selectivecps/CPSAnnotationChecker.scala b/src/continuations/plugin/scala/tools/selectivecps/CPSAnnotationChecker.scala index 600b51f376..beab271a3b 100644 --- a/src/continuations/plugin/scala/tools/selectivecps/CPSAnnotationChecker.scala +++ b/src/continuations/plugin/scala/tools/selectivecps/CPSAnnotationChecker.scala @@ -8,6 +8,7 @@ import scala.tools.nsc.MissingRequirementError abstract class CPSAnnotationChecker extends CPSUtils { val global: Global import global._ + import analyzer.{AnalyzerPlugin, Typer} import definitions._ //override val verbose = true @@ -17,12 +18,12 @@ abstract class CPSAnnotationChecker extends CPSUtils { * Checks whether @cps annotations conform */ object checker extends AnnotationChecker { - private def addPlusMarker(tp: Type) = tp withAnnotation newPlusMarker() - private def addMinusMarker(tp: Type) = tp withAnnotation newMinusMarker() + private[CPSAnnotationChecker] def addPlusMarker(tp: Type) = tp withAnnotation newPlusMarker() + private[CPSAnnotationChecker] def addMinusMarker(tp: Type) = tp withAnnotation newMinusMarker() - private def cleanPlus(tp: Type) = + private[CPSAnnotationChecker] def cleanPlus(tp: Type) = removeAttribs(tp, MarkerCPSAdaptPlus, MarkerCPSTypes) - private def cleanPlusWith(tp: Type)(newAnnots: AnnotationInfo*) = + private[CPSAnnotationChecker] def cleanPlusWith(tp: Type)(newAnnots: AnnotationInfo*) = cleanPlus(tp) withAnnotations newAnnots.toList /** Check annotations to decide whether tpe1 <:< tpe2 */ @@ -115,8 +116,13 @@ abstract class CPSAnnotationChecker extends CPSUtils { } else bounds } + } + + object plugin extends AnalyzerPlugin { + + import checker._ - override def canAdaptAnnotations(tree: Tree, mode: Mode, pt: Type): Boolean = { + override def canAdaptAnnotations(tree: Tree, typer: Typer, mode: Mode, pt: Type): Boolean = { if (!cpsEnabled) return false vprintln("can adapt annotations? " + tree + " / " + tree.tpe + " / " + mode + " / " + pt) @@ -182,7 +188,7 @@ abstract class CPSAnnotationChecker extends CPSUtils { } else false } - override def adaptAnnotations(tree: Tree, mode: Mode, pt: Type): Tree = { + override def adaptAnnotations(tree: Tree, typer: Typer, mode: Mode, pt: Type): Tree = { if (!cpsEnabled) return tree vprintln("adapt annotations " + tree + " / " + tree.tpe + " / " + mode + " / " + pt) @@ -238,14 +244,15 @@ abstract class CPSAnnotationChecker extends CPSUtils { * is in tail position. Therefore, we are making sure that only the types of return expressions * are adapted which will either be removed, or lead to an error. */ - override def adaptTypeOfReturn(tree: Tree, pt: Type, default: => Type): Type = { + override def pluginsTypedReturn(default: Type, typer: Typer, tree: Return, pt: Type): Type = { + val expr = tree.expr // only adapt if method's result type (pt) is cps type val annots = cpsParamAnnotation(pt) if (annots.nonEmpty) { - // return type of `tree` without plus marker, but only if it doesn't have other cps annots - if (hasPlusMarker(tree.tpe) && !hasCpsParamTypes(tree.tpe)) - tree.setType(removeAttribs(tree.tpe, MarkerCPSAdaptPlus)) - tree.tpe + // return type of `expr` without plus marker, but only if it doesn't have other cps annots + if (hasPlusMarker(expr.tpe) && !hasCpsParamTypes(expr.tpe)) + expr.setType(removeAttribs(expr.tpe, MarkerCPSAdaptPlus)) + expr.tpe } else default } @@ -392,7 +399,7 @@ abstract class CPSAnnotationChecker extends CPSUtils { /** Modify the type that has thus far been inferred * for a tree. All this should do is add annotations. */ - override def addAnnotations(tree: Tree, tpe: Type): Type = { + override def pluginsTyped(tpe: Type, typer: Typer, tree: Tree, mode: Mode, pt: Type): Type = { import scala.util.control._ if (!cpsEnabled) { val report = try hasCpsParamTypes(tpe) catch { case _: MissingRequirementError => false } diff --git a/src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSPlugin.scala b/src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSPlugin.scala index 90e64d8171..c16cce2f2c 100644 --- a/src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSPlugin.scala +++ b/src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSPlugin.scala @@ -28,6 +28,7 @@ class SelectiveCPSPlugin(val global: Global) extends Plugin { val global: SelectiveCPSPlugin.this.global.type = SelectiveCPSPlugin.this.global } global.addAnnotationChecker(checker.checker) + global.analyzer.addAnalyzerPlugin(checker.plugin) global.log("instantiated cps plugin: " + this) |