blob: 79f544cfe8caf0468171be4e6173d6adafda72bc (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
package scala.async.internal
import scala.tools.nsc.Global
import scala.tools.nsc.transform.TypingTransformers
object AsyncMacro {
def apply(c: reflect.macros.Context, base: AsyncBase): AsyncMacro = {
import language.reflectiveCalls
val powerContext = c.asInstanceOf[c.type { val universe: Global; val callsiteTyper: universe.analyzer.Typer }]
new AsyncMacro {
val global: powerContext.universe.type = powerContext.universe
val callSiteTyper: global.analyzer.Typer = powerContext.callsiteTyper
val macroApplication: global.Tree = c.macroApplication.asInstanceOf[global.Tree]
// This member is required by `AsyncTransform`:
val asyncBase: AsyncBase = base
// These members are required by `ExprBuilder`:
val futureSystem: FutureSystem = base.futureSystem
val futureSystemOps: futureSystem.Ops {val universe: global.type} = futureSystem.mkOps(global)
}
}
}
private[async] trait AsyncMacro
extends TypingTransformers
with AnfTransform with TransformUtils with Lifter
with ExprBuilder with AsyncTransform with AsyncAnalysis with LiveVariables {
val global: Global
val callSiteTyper: global.analyzer.Typer
val macroApplication: global.Tree
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
import global.Tree
type Suppress = { def suppressMacroExpansion(a: Tree): Tree }
try {
global.asInstanceOf[Suppress].suppressMacroExpansion(macroApplication)
} catch {
case _: NoSuchMethodException =>
global.analyzer.asInstanceOf[Suppress].suppressMacroExpansion(macroApplication)
}
}
}
|