From e967d354486a226c2fe8f0866e53f805e94f3e53 Mon Sep 17 00:00:00 2001 From: Mark Harrah Date: Mon, 20 Aug 2012 15:55:50 -0400 Subject: [PATCH] move explicit task/setting macros to Def, move to AbsTypeTag --- util/appmacro/ContextUtil.scala | 12 +++++++----- util/appmacro/Instance.scala | 11 ++++++----- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/util/appmacro/ContextUtil.scala b/util/appmacro/ContextUtil.scala index 8be859494..2451c7c98 100644 --- a/util/appmacro/ContextUtil.scala +++ b/util/appmacro/ContextUtil.scala @@ -18,15 +18,17 @@ final class ContextUtil[C <: Context](val ctx: C) { import ctx.universe.{Apply=>ApplyTree,_} - val alistType = ctx.typeOf[AList[KList]] - val alist: Symbol = alistType.typeSymbol.companionSymbol - val alistTC: Type = alistType.typeConstructor + lazy val alistType = ctx.typeOf[AList[KList]] + lazy val alist: Symbol = alistType.typeSymbol.companionSymbol + lazy val alistTC: Type = alistType.typeConstructor /** Modifiers for a local val.*/ - val localModifiers = Modifiers(NoFlags) + lazy val localModifiers = Modifiers(NoFlags) def getPos(sym: Symbol) = if(sym eq null) NoPosition else sym.pos + def atypeOf[T](implicit att: AbsTypeTag[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)) @@ -58,7 +60,7 @@ final class ContextUtil[C <: Context](val ctx: C) owner.asInstanceOf[global.Symbol].newSyntheticTypeParam(prefix, 0L).asInstanceOf[ctx.universe.TypeSymbol] } /** The type representing the type constructor `[X] X` */ - val idTC: Type = + lazy val idTC: Type = { val tvar = newTypeVariable(NoSymbol) polyType(tvar :: Nil, refVar(tvar)) diff --git a/util/appmacro/Instance.scala b/util/appmacro/Instance.scala index 6dec0eabc..71360c1c7 100644 --- a/util/appmacro/Instance.scala +++ b/util/appmacro/Instance.scala @@ -18,7 +18,7 @@ trait Instance } trait Convert { - def apply[T: c.TypeTag](c: scala.reflect.makro.Context)(in: c.Tree): c.Tree + def apply[T: c.AbsTypeTag](c: scala.reflect.makro.Context)(in: c.Tree): c.Tree } trait MonadInstance extends Instance { @@ -80,18 +80,19 @@ object Instance * If this is for multi-input flatMap (app followed by flatMap), * this should be the argument wrapped in Right. */ - def contImpl[T: c.TypeTag](c: Context, i: Instance with Singleton, convert: Convert, builder: TupleBuilder)(t: Either[c.Expr[T], c.Expr[i.M[T]]])( - implicit tt: c.TypeTag[T], mt: c.TypeTag[i.M[T]], it: c.TypeTag[i.type]): c.Expr[i.M[T]] = + def contImpl[T](c: Context, i: Instance with Singleton, convert: Convert, builder: TupleBuilder)(t: Either[c.Expr[T], c.Expr[i.M[T]]])( + implicit tt: c.AbsTypeTag[T], it: c.TypeTag[i.type]): c.Expr[i.M[T]] = { import c.universe.{Apply=>ApplyTree,_} val util = ContextUtil[c.type](c) val mTC: Type = util.extractTC(i, InstanceTCName) + val mttpe: Type = appliedType(mTC, tt.tpe :: Nil).normalize // the tree for the macro argument val (tree, treeType) = t match { case Left(l) => (l.tree, tt.tpe.normalize) - case Right(r) => (r.tree, mt.tpe.normalize) + case Right(r) => (r.tree, mttpe) } val instanceSym = util.singleton(i) @@ -202,7 +203,7 @@ object Instance tree match { case ApplyTree(TypeApply(fun, t :: Nil), qual :: Nil) if isWrapper(fun) => - val tag = c.TypeTag(t.tpe) + val tag = c.AbsTypeTag(t.tpe) addType(t.tpe, convert(c)(qual)(tag) ) case _ => super.transform(tree) }