use standard Context.weakTypeOf

This commit is contained in:
Mark Harrah 2013-01-28 17:14:53 -05:00
parent 076480b50a
commit 13ea342b7a
3 changed files with 6 additions and 12 deletions

View File

@ -17,10 +17,9 @@ object InitializeConvert extends Convert
{
def apply[T: c.WeakTypeTag](c: reflect.macros.Context)(in: c.Tree): c.Tree =
{
val u = appmacro.ContextUtil[c.type](c)
if(in.tpe <:< u.atypeOf[Initialize[Task[T]]] || in.tpe <:< u.atypeOf[Task[T]])
if(in.tpe <:< c.weakTypeOf[Initialize[Task[T]]] || in.tpe <:< c.weakTypeOf[Task[T]])
c.abort(in.pos, "A setting cannot depend on a task")
else if(in.tpe <:< u.atypeOf[Initialize[T]])
else if(in.tpe <:< c.weakTypeOf[Initialize[T]])
{
val i = c.Expr[Initialize[T]](in)
c.universe.reify( i.splice ).tree

View File

@ -52,23 +52,20 @@ object FullInstance extends Instance.Composed[Initialize, Task](InitializeInstan
object FullConvert extends Convert
{
def apply[T: c.WeakTypeTag](c: Context)(in: c.Tree): c.Tree =
{
val util = appmacro.ContextUtil[c.type](c)
if(in.tpe <:< util.atypeOf[Initialize[Task[T]]])
if(in.tpe <:< c.weakTypeOf[Initialize[Task[T]]])
in
else if(in.tpe <:< util.atypeOf[Initialize[T]])
else if(in.tpe <:< c.weakTypeOf[Initialize[T]])
{
val i = c.Expr[Initialize[T]](in)
c.universe.reify( Def.toITask(i.splice) ).tree
}
else if(in.tpe <:< util.atypeOf[Task[T]])
else if(in.tpe <:< c.weakTypeOf[Task[T]])
{
val i = c.Expr[Task[T]](in)
c.universe.reify( Def.valueStrict[Task[T]](i.splice) ).tree
}
else
c.abort(in.pos, "Unknown input type: " + in.tpe)
}
}
object TaskMacro
@ -348,7 +345,7 @@ object TaskConvert extends Convert
def apply[T: c.WeakTypeTag](c: Context)(in: c.Tree): c.Tree =
{
val u = appmacro.ContextUtil[c.type](c)
if(in.tpe <:< u.atypeOf[Task[T]])
if(in.tpe <:< c.weakTypeOf[Task[T]])
in
else
c.abort(in.pos, "Unknown input type: " + in.tpe)

View File

@ -48,8 +48,6 @@ final class ContextUtil[C <: Context](val ctx: C)
def getPos(sym: Symbol) = if(sym eq null) NoPosition else sym.pos
def atypeOf[T](implicit att: WeakTypeTag[T]): Type = att.tpe
/** Constructs a unique term name with the given prefix within this Context.
* (The current implementation uses Context.fresh, which increments*/
def freshTermName(prefix: String) = newTermName(ctx.fresh("$" + prefix))