deprecations

This commit is contained in:
Mark Harrah 2013-02-25 09:24:04 -05:00
parent 13e1b00436
commit d426035da3
4 changed files with 16 additions and 14 deletions

View File

@ -29,7 +29,7 @@ object ContextUtil {
} }
} }
def unexpectedTree[C <: Context](tree: C#Tree): Nothing = error("Unexpected macro application tree (" + tree.getClass + "): " + tree) def unexpectedTree[C <: Context](tree: C#Tree): Nothing = sys.error("Unexpected macro application tree (" + tree.getClass + "): " + tree)
} }
/** Utility methods for macros. Several methods assume that the context's universe is a full compiler (`scala.tools.nsc.Global`). /** Utility methods for macros. Several methods assume that the context's universe is a full compiler (`scala.tools.nsc.Global`).
@ -161,9 +161,11 @@ final class ContextUtil[C <: Context](val ctx: C)
def singleton[T <: AnyRef with Singleton](i: T)(implicit it: ctx.TypeTag[i.type]): Symbol = def singleton[T <: AnyRef with Singleton](i: T)(implicit it: ctx.TypeTag[i.type]): Symbol =
it.tpe match { it.tpe match {
case SingleType(_, sym) if !sym.isFreeTerm && sym.isStatic => sym case SingleType(_, sym) if !sym.isFreeTerm && sym.isStatic => sym
case x => error("Instance must be static (was " + x + ").") case x => sys.error("Instance must be static (was " + x + ").")
} }
def select(t: Tree, name: String): Tree = Select(t, newTermName(name))
/** Returns the symbol for the non-private method named `name` for the class/module `obj`. */ /** Returns the symbol for the non-private method named `name` for the class/module `obj`. */
def method(obj: Symbol, name: String): Symbol = { def method(obj: Symbol, name: String): Symbol = {
val global: Global = ctx.universe.asInstanceOf[Global] val global: Global = ctx.universe.asInstanceOf[Global]

View File

@ -38,7 +38,7 @@ object InputWrapper
final val WrapName = "wrap_\u2603\u2603" final val WrapName = "wrap_\u2603\u2603"
@compileTimeOnly("`value` can only be used within a task or setting macro, such as :=, +=, ++=, Def.task, or Def.setting.") @compileTimeOnly("`value` can only be used within a task or setting macro, such as :=, +=, ++=, Def.task, or Def.setting.")
def wrap_\u2603\u2603[T](in: Any): T = error("This method is an implementation detail and should not be referenced.") def wrap_\u2603\u2603[T](in: Any): T = sys.error("This method is an implementation detail and should not be referenced.")
def wrapKey[T: c.WeakTypeTag](c: Context)(ts: c.Expr[Any], pos: c.Position): c.Expr[T] = wrapImpl[T,InputWrapper.type](c, InputWrapper, WrapName)(ts, pos) def wrapKey[T: c.WeakTypeTag](c: Context)(ts: c.Expr[Any], pos: c.Position): c.Expr[T] = wrapImpl[T,InputWrapper.type](c, InputWrapper, WrapName)(ts, pos)
@ -54,7 +54,7 @@ object InputWrapper
val iw = util.singleton(s) val iw = util.singleton(s)
val tpe = c.weakTypeOf[T] val tpe = c.weakTypeOf[T]
val nme = newTermName(wrapName).encoded val nme = newTermName(wrapName).encoded
val sel = Select(Ident(iw), nme) val sel = util.select(Ident(iw), nme)
sel.setPos(pos) // need to set the position on Select, because that is where the compileTimeOnly check looks sel.setPos(pos) // need to set the position on Select, because that is where the compileTimeOnly check looks
val tree = ApplyTree(TypeApply(sel, TypeTree(tpe) :: Nil), ts.tree :: Nil) val tree = ApplyTree(TypeApply(sel, TypeTree(tpe) :: Nil), ts.tree :: Nil)
tree.setPos(ts.tree.pos) tree.setPos(ts.tree.pos)
@ -147,7 +147,7 @@ object Instance
// no inputs, so construct M[T] via Instance.pure or pure+flatten // no inputs, so construct M[T] via Instance.pure or pure+flatten
def pure(body: Tree): Tree = def pure(body: Tree): Tree =
{ {
val typeApplied = TypeApply(Select(instance, PureName), TypeTree(treeType) :: Nil) val typeApplied = TypeApply(util.select(instance, PureName), TypeTree(treeType) :: Nil)
val p = ApplyTree(typeApplied, Function(Nil, body) :: Nil) val p = ApplyTree(typeApplied, Function(Nil, body) :: Nil)
if(t.isLeft) p else flatten(p) if(t.isLeft) p else flatten(p)
} }
@ -155,7 +155,7 @@ object Instance
// the returned Tree will have type M[T] // the returned Tree will have type M[T]
def flatten(m: Tree): Tree = def flatten(m: Tree): Tree =
{ {
val typedFlatten = TypeApply(Select(instance, FlattenName), TypeTree(tt.tpe) :: Nil) val typedFlatten = TypeApply(util.select(instance, FlattenName), TypeTree(tt.tpe) :: Nil)
ApplyTree(typedFlatten, m :: Nil) ApplyTree(typedFlatten, m :: Nil)
} }
@ -164,7 +164,7 @@ object Instance
{ {
val variable = input.local val variable = input.local
val param = ValDef(util.parameterModifiers, variable.name, variable.tpt, EmptyTree) val param = ValDef(util.parameterModifiers, variable.name, variable.tpt, EmptyTree)
val typeApplied = TypeApply(Select(instance, MapName), variable.tpt :: TypeTree(treeType) :: Nil) val typeApplied = TypeApply(util.select(instance, MapName), variable.tpt :: TypeTree(treeType) :: Nil)
val mapped = ApplyTree(typeApplied, input.expr :: Function(param :: Nil, body) :: Nil) val mapped = ApplyTree(typeApplied, input.expr :: Function(param :: Nil, body) :: Nil)
if(t.isLeft) mapped else flatten(mapped) if(t.isLeft) mapped else flatten(mapped)
} }
@ -177,7 +177,7 @@ object Instance
val bindings = result.extract(param) val bindings = result.extract(param)
val f = Function(param :: Nil, Block(bindings, body)) val f = Function(param :: Nil, Block(bindings, body))
val ttt = TypeTree(treeType) val ttt = TypeTree(treeType)
val typedApp = TypeApply(Select(instance, ApplyName), TypeTree(result.representationC) :: ttt :: Nil) val typedApp = TypeApply(util.select(instance, ApplyName), TypeTree(result.representationC) :: ttt :: Nil)
val app = ApplyTree(ApplyTree(typedApp, result.input :: f :: Nil), result.alistInstance :: Nil) val app = ApplyTree(ApplyTree(typedApp, result.input :: f :: Nil), result.alistInstance :: Nil)
if(t.isLeft) app else flatten(app) if(t.isLeft) app else flatten(app)
} }

View File

@ -34,8 +34,8 @@ object KListBuilder extends TupleBuilder
params match params match
{ {
case ValDef(mods, name, tpt, _) :: xs => case ValDef(mods, name, tpt, _) :: xs =>
val head = ValDef(mods, name, tpt, Select(Ident(prev.name), "head")) val head = ValDef(mods, name, tpt, select(Ident(prev.name), "head"))
val tail = localValDef(TypeTree(), Select(Ident(prev.name), "tail")) val tail = localValDef(TypeTree(), select(Ident(prev.name), "tail"))
val base = head :: revBindings val base = head :: revBindings
bindKList(tail, if(xs.isEmpty) base else tail :: base, xs) bindKList(tail, if(xs.isEmpty) base else tail :: base, xs)
case Nil => revBindings.reverse case Nil => revBindings.reverse
@ -60,7 +60,7 @@ object KListBuilder extends TupleBuilder
val representationC = PolyType(tcVariable :: Nil, klistType) val representationC = PolyType(tcVariable :: Nil, klistType)
val resultType = appliedType(representationC, idTC :: Nil) val resultType = appliedType(representationC, idTC :: Nil)
val input = klist val input = klist
val alistInstance = TypeApply(Select(Ident(alist), "klist"), TypeTree(representationC) :: Nil) val alistInstance = TypeApply(select(Ident(alist), "klist"), TypeTree(representationC) :: Nil)
def extract(param: ValDef) = bindKList(param, Nil, inputs.map(_.local)) def extract(param: ValDef) = bindKList(param, Nil, inputs.map(_.local))
} }
} }

View File

@ -34,8 +34,8 @@ object TupleNBuilder extends TupleBuilder
val input: Tree = mkTuple(inputs.map(_.expr)) val input: Tree = mkTuple(inputs.map(_.expr))
val alistInstance: Tree = { val alistInstance: Tree = {
val select = Select(Ident(alist), TupleMethodName + inputs.size.toString) val selectTree = select(Ident(alist), TupleMethodName + inputs.size.toString)
TypeApply(select, inputs.map(in => TypeTree(in.tpe))) TypeApply(selectTree, inputs.map(in => TypeTree(in.tpe)))
} }
def extract(param: ValDef): List[ValDef] = bindTuple(param, Nil, inputs.map(_.local), 1) def extract(param: ValDef): List[ValDef] = bindTuple(param, Nil, inputs.map(_.local), 1)
@ -43,7 +43,7 @@ object TupleNBuilder extends TupleBuilder
params match params match
{ {
case ValDef(mods, name, tpt, _) :: xs => case ValDef(mods, name, tpt, _) :: xs =>
val x = ValDef(mods, name, tpt, Select(Ident(param.name), "_" + i.toString)) val x = ValDef(mods, name, tpt, select(Ident(param.name), "_" + i.toString))
bindTuple(param, x :: revBindings, xs, i+1) bindTuple(param, x :: revBindings, xs, i+1)
case Nil => revBindings.reverse case Nil => revBindings.reverse
} }