Skip to content

minor cleanups accumulated while reading the code #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 27, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions src/main/scala/scala/async/AnfTransform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private[async] final case class AnfTransform[C <: Context](c: C) {
val origName = defTree.symbol.name
val sym = defTree.symbol.asInstanceOf[symtab.Symbol]
val fresh = name.fresh(sym.name.toString)
sym.name = defTree.symbol.name match {
sym.name = origName match {
case _: TermName => symtab.newTermName(fresh)
case _: TypeName => symtab.newTypeName(fresh)
}
Expand Down Expand Up @@ -184,14 +184,15 @@ private[async] final case class AnfTransform[C <: Context](c: C) {
private object anf {

private[AnfTransform] def transformToList(tree: Tree): List[Tree] = trace("anf", tree) {
def containsAwait = tree exists isAwait

tree match {
case Select(qual, sel) if containsAwait =>
val containsAwait = tree exists isAwait
if (!containsAwait) {
List(tree)
} else tree match {
case Select(qual, sel) =>
val stats :+ expr = inline.transformToList(qual)
stats :+ attachCopy(tree)(Select(expr, sel).setSymbol(tree.symbol))

case Applied(fun, targs, argss) if argss.nonEmpty && containsAwait =>
case Applied(fun, targs, argss) if argss.nonEmpty =>
// we an assume that no await call appears in a by-name argument position,
// this has already been checked.
val funStats :+ simpleFun = inline.transformToList(fun)
Expand All @@ -210,20 +211,20 @@ private[async] final case class AnfTransform[C <: Context](c: C) {
val core = if (targs.isEmpty) simpleFun else TypeApply(simpleFun, targs)
val newApply = argExprss.foldLeft(core)(Apply(_, _).setSymbol(tree.symbol))
funStats ++ argStatss.flatten.flatten :+ attachCopy(tree)(newApply)
case Block(stats, expr) if containsAwait =>
case Block(stats, expr) =>
inline.transformToList(stats :+ expr)

case ValDef(mods, name, tpt, rhs) if containsAwait =>
case ValDef(mods, name, tpt, rhs) =>
if (rhs exists isAwait) {
val stats :+ expr = inline.transformToList(rhs)
stats :+ attachCopy(tree)(ValDef(mods, name, tpt, expr).setSymbol(tree.symbol))
} else List(tree)

case Assign(lhs, rhs) if containsAwait =>
case Assign(lhs, rhs) =>
val stats :+ expr = inline.transformToList(rhs)
stats :+ attachCopy(tree)(Assign(lhs, expr))

case If(cond, thenp, elsep) if containsAwait =>
case If(cond, thenp, elsep) =>
val condStats :+ condExpr = inline.transformToList(cond)
val thenBlock = inline.transformToBlock(thenp)
val elseBlock = inline.transformToBlock(elsep)
Expand All @@ -237,7 +238,7 @@ private[async] final case class AnfTransform[C <: Context](c: C) {
condStats :+
attachCopy(tree)(If(condExpr, thenBlock, elseBlock)).setType(ifType)

case Match(scrut, cases) if containsAwait =>
case Match(scrut, cases) =>
val scrutStats :+ scrutExpr = inline.transformToList(scrut)
val caseDefs = cases map {
case CaseDef(pat, guard, body) =>
Expand All @@ -259,10 +260,10 @@ private[async] final case class AnfTransform[C <: Context](c: C) {
val typedMatch = attachCopy(tree)(Match(scrutExpr, caseDefs)).setType(tree.tpe)
scrutStats :+ typedMatch

case LabelDef(name, params, rhs) if containsAwait =>
case LabelDef(name, params, rhs) =>
List(LabelDef(name, params, Block(inline.transformToList(rhs), Literal(Constant(())))).setSymbol(tree.symbol))

case TypeApply(fun, targs) if containsAwait =>
case TypeApply(fun, targs) =>
val funStats :+ simpleFun = inline.transformToList(fun)
funStats :+ attachCopy(tree)(TypeApply(simpleFun, targs).setSymbol(tree.symbol))

Expand Down