diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2013-11-20 09:13:41 -0800 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2013-11-20 09:13:41 -0800 |
commit | 72848bdfc0c2000b8890f24be88c06d077a36a0a (patch) | |
tree | e428a6ee0fdcd10109331cb3c3411f21d3014878 /src/main | |
parent | 0cc77d140a882a8bbbc7fdc123625459227c5d81 (diff) | |
parent | e9040d9ee14d620248a159e90a8fa483064f73f8 (diff) | |
download | scala-async-72848bdfc0c2000b8890f24be88c06d077a36a0a.tar.gz scala-async-72848bdfc0c2000b8890f24be88c06d077a36a0a.tar.bz2 scala-async-72848bdfc0c2000b8890f24be88c06d077a36a0a.zip |
Merge pull request #46 from retronym/topic/pres-compiler-npe
Presentation compiler friendliness
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/scala/scala/async/internal/AsyncBase.scala | 20 | ||||
-rw-r--r-- | src/main/scala/scala/async/internal/AsyncMacro.scala | 17 | ||||
-rw-r--r-- | src/main/scala/scala/async/internal/TransformUtils.scala | 1 |
3 files changed, 31 insertions, 7 deletions
diff --git a/src/main/scala/scala/async/internal/AsyncBase.scala b/src/main/scala/scala/async/internal/AsyncBase.scala index 8cacb40..3bb3b99 100644 --- a/src/main/scala/scala/async/internal/AsyncBase.scala +++ b/src/main/scala/scala/async/internal/AsyncBase.scala @@ -43,20 +43,26 @@ abstract class AsyncBase { (body: c.Expr[T]) (execContext: c.Expr[futureSystem.ExecContext]): c.Expr[futureSystem.Fut[T]] = { import c.universe._ - val asyncMacro = AsyncMacro(c, self) + val isPresentationCompiler = asyncMacro.global.forInteractive + val code = asyncMacro.asyncTransform[T]( body.tree.asInstanceOf[asyncMacro.global.Tree], execContext.tree.asInstanceOf[asyncMacro.global.Tree] - )(implicitly[c.WeakTypeTag[T]].asInstanceOf[asyncMacro.global.WeakTypeTag[T]]).asInstanceOf[Tree] - - // Mark range positions for synthetic code as transparent to allow some wiggle room for overlapping ranges - for (t <- code) - t.pos = t.pos.makeTransparent + )(implicitly[c.WeakTypeTag[T]].asInstanceOf[asyncMacro.global.WeakTypeTag[T]]).asInstanceOf[Tree] AsyncUtils.vprintln(s"async state machine transform expands to:\n ${code}") - c.Expr[futureSystem.Fut[T]](code) + val result = if (isPresentationCompiler) { + asyncMacro.suppressExpansion() + c.macroApplication + } else { + // Mark range positions for synthetic code as transparent to allow some wiggle room for overlapping ranges + for (t <- code) + t.pos = t.pos.makeTransparent + code + } + c.Expr[futureSystem.Fut[T]](result) } protected[async] def awaitMethod(u: Universe)(asyncMacroSymbol: u.Symbol): u.Symbol = { diff --git a/src/main/scala/scala/async/internal/AsyncMacro.scala b/src/main/scala/scala/async/internal/AsyncMacro.scala index ee49923..d030367 100644 --- a/src/main/scala/scala/async/internal/AsyncMacro.scala +++ b/src/main/scala/scala/async/internal/AsyncMacro.scala @@ -32,4 +32,21 @@ private[async] trait AsyncMacro lazy val macroPos = macroApplication.pos.makeTransparent def atMacroPos(t: global.Tree) = global.atPos(macroPos)(t) + def suppressExpansion() { + // Have your cake : Scala IDE sees original trees and hyperlinking, etc within async blocks "Just Works" + // Eat it too : (domain specific errors like "unsupported use of await" + // + // TODO roll this idea back into scala/scala + def suppress(globalOrAnalzer: Any) = { + type Suppress = { def suppressMacroExpansion(a: Object): Object } + globalOrAnalzer.asInstanceOf[Suppress].suppressMacroExpansion(macroApplication) + } + try { + suppress(global) // 2.10.x + } catch { + case _: NoSuchMethodException => + suppress(global.analyzer) // 2.11 + } + } + } diff --git a/src/main/scala/scala/async/internal/TransformUtils.scala b/src/main/scala/scala/async/internal/TransformUtils.scala index 92c9a4f..71fddaa 100644 --- a/src/main/scala/scala/async/internal/TransformUtils.scala +++ b/src/main/scala/scala/async/internal/TransformUtils.scala @@ -203,6 +203,7 @@ private[async] trait TransformUtils { abstract class MacroTypingTransformer extends TypingTransformer(callSiteTyper.context.unit) { currentOwner = callSiteTyper.context.owner + curTree = EmptyTree def currOwner: Symbol = currentOwner |