@@ -5,15 +5,17 @@ package scala.async.internal
55
66import scala .reflect .macros .Context
77import reflect .ClassTag
8+ import scala .collection .immutable .ListMap
89
910/**
1011 * Utilities used in both `ExprBuilder` and `AnfTransform`.
1112 */
1213private [async] trait TransformUtils {
1314 self : AsyncMacro =>
1415
15- import c .universe .{ gen => _ , _ }
16+ import c .universe ._
1617 import c .internal ._
18+ import decorators ._
1719
1820 object name {
1921 val resume = newTermName(" resume" )
@@ -51,7 +53,7 @@ private[async] trait TransformUtils {
5153 if (Boolean_ShortCircuits contains fun.symbol) (i, j) => true
5254 else {
5355 val paramss = fun.tpe.paramss
54- val byNamess = paramss.map(_.map(_.isByNameParam))
56+ val byNamess = paramss.map(_.map(_.asTerm. isByNameParam))
5557 (i, j) => util.Try (byNamess(i)(j)).getOrElse(false )
5658 }
5759 }
@@ -86,10 +88,6 @@ private[async] trait TransformUtils {
8688 val Async_await = asyncBase.awaitMethod(c.universe)(c.macroApplication.symbol).ensuring(_ != NoSymbol )
8789 }
8890
89- def isSafeToInline (tree : Tree ) = {
90- treeInfo.isExprSafeToInline(tree)
91- }
92-
9391 // `while(await(x))` ... or `do { await(x); ... } while(...)` contain an `If` that loops;
9492 // we must break that `If` into states so that it convert the label jump into a state machine
9593 // transition
@@ -192,7 +190,7 @@ private[async] trait TransformUtils {
192190 case dd : DefDef => nestedMethod(dd)
193191 case fun : Function => function(fun)
194192 case m@ Match (EmptyTree , _) => patMatFunction(m) // Pattern matching anonymous function under -Xoldpatmat of after `restorePatternMatchingFunctions`
195- case treeInfo. Applied ( fun, targs, argss) if argss.nonEmpty =>
193+ case q " $ fun[.. $ targs](... $ argss) " if argss.nonEmpty =>
196194 val isInByName = isByName(fun)
197195 for ((args, i) <- argss.zipWithIndex) {
198196 for ((arg, j) <- args.zipWithIndex) {
@@ -219,11 +217,42 @@ private[async] trait TransformUtils {
219217 // Attributed version of `TreeGen#mkCastPreservingAnnotations`
220218 def mkAttributedCastPreservingAnnotations (tree : Tree , tp : Type ): Tree = {
221219 atPos(tree.pos) {
222- val casted = c.typecheck(gen.mkCast(tree, uncheckedBounds(tp. withoutAnnotations).dealias))
220+ val casted = c.typecheck(gen.mkCast(tree, uncheckedBounds(withoutAnnotations(tp) ).dealias))
223221 Typed (casted, TypeTree (tp)).setType(tp)
224222 }
225223 }
226224
225+ def deconst (tp : Type ): Type = tp match {
226+ case AnnotatedType (anns, underlying) => annotatedType(anns, deconst(underlying))
227+ case ExistentialType (quants, underlying) => existentialType(quants, deconst(underlying))
228+ case ConstantType (value) => deconst(value.tpe)
229+ case _ => tp
230+ }
231+
232+ def withAnnotation (tp : Type , ann : Annotation ): Type = withAnnotations(tp, List (ann))
233+
234+ def withAnnotations (tp : Type , anns : List [Annotation ]): Type = tp match {
235+ case AnnotatedType (existingAnns, underlying) => annotatedType(anns ::: existingAnns, underlying)
236+ case ExistentialType (quants, underlying) => existentialType(quants, withAnnotations(underlying, anns))
237+ case _ => annotatedType(anns, tp)
238+ }
239+
240+ def withoutAnnotations (tp : Type ): Type = tp match {
241+ case AnnotatedType (anns, underlying) => withoutAnnotations(underlying)
242+ case ExistentialType (quants, underlying) => existentialType(quants, withoutAnnotations(underlying))
243+ case _ => tp
244+ }
245+
246+ def tpe (sym : Symbol ): Type = {
247+ if (sym.isType) sym.asType.toType
248+ else sym.info
249+ }
250+
251+ def thisType (sym : Symbol ): Type = {
252+ if (sym.isClass) sym.asClass.thisPrefix
253+ else NoPrefix
254+ }
255+
227256 // =====================================
228257 // Copy/Pasted from Scala 2.10.3. See SI-7694.
229258 private lazy val UncheckedBoundsClass = {
@@ -232,7 +261,7 @@ private[async] trait TransformUtils {
232261 }
233262 final def uncheckedBounds (tp : Type ): Type = {
234263 if (tp.typeArgs.isEmpty || UncheckedBoundsClass == NoSymbol ) tp
235- else tp. withAnnotation(AnnotationInfo marker UncheckedBoundsClass .tpe )
264+ else withAnnotation(tp, Annotation ( UncheckedBoundsClass .asType.toType, Nil , ListMap ()) )
236265 }
237266 // =====================================
238267}
0 commit comments