aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/typer
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2013-07-27 19:48:30 +0200
committerMartin Odersky <odersky@gmail.com>2013-07-27 19:48:30 +0200
commit60b3469ac70052b762cc7bf0d36bf2ec37e8e6dc (patch)
tree2aaf9fff135e0ac94a3a44457d3523eee02c01f7 /src/dotty/tools/dotc/typer
parentcf65e84a6da2a151286a36297c057b72545960c8 (diff)
downloaddotty-60b3469ac70052b762cc7bf0d36bf2ec37e8e6dc.tar.gz
dotty-60b3469ac70052b762cc7bf0d36bf2ec37e8e6dc.tar.bz2
dotty-60b3469ac70052b762cc7bf0d36bf2ec37e8e6dc.zip
Redesign of trees.
1) Trees are now contravariant. 2) All creation ops, transformers, copiers are pushed into Instance. 3) Still to do: integrate TreeMappers and tpd.TreeTransformers.
Diffstat (limited to 'src/dotty/tools/dotc/typer')
-rw-r--r--src/dotty/tools/dotc/typer/Applications.scala65
-rw-r--r--src/dotty/tools/dotc/typer/EtaExpansion.scala8
-rw-r--r--src/dotty/tools/dotc/typer/Namer.scala6
-rw-r--r--src/dotty/tools/dotc/typer/Typer.scala39
4 files changed, 59 insertions, 59 deletions
diff --git a/src/dotty/tools/dotc/typer/Applications.scala b/src/dotty/tools/dotc/typer/Applications.scala
index 3ce735c12..6424b96e4 100644
--- a/src/dotty/tools/dotc/typer/Applications.scala
+++ b/src/dotty/tools/dotc/typer/Applications.scala
@@ -27,7 +27,7 @@ import language.implicitConversions
object Applications {
- import tpd._
+ import tpd.{ cpy => _, _ }
private val isNamedArg = (arg: Any) => arg.isInstanceOf[Trees.NamedArg[_]]
def hasNamedArg(args: List[Any]) = args exists isNamedArg
@@ -44,10 +44,9 @@ object Applications {
* 3. there is an implicit conversion from `tp` to `pt`.
*/
def isCompatible(tp: Type, pt: Type)(implicit ctx: Context): Boolean = (
- tp <:< pt
- || pt.typeSymbol == defn.ByNameParamClass && tp <:< pt.typeArgs.head
- || viewExists(tp, pt)
- )
+ tp <:< pt
+ || pt.typeSymbol == defn.ByNameParamClass && tp <:< pt.typeArgs.head
+ || viewExists(tp, pt))
}
/** The normalized form of a type
@@ -82,15 +81,15 @@ object Applications {
import Applications._
-trait Applications extends Compatibility{ self: Typer =>
+trait Applications extends Compatibility { self: Typer =>
import Applications._
- import tpd._
+ import tpd.{ cpy => _, _ }
+ import untpd.cpy
private def state(implicit ctx: Context) = ctx.typerState
- /**
- * @param Arg the type of arguments, could be tpd.Tree, untpd.Tree, or Type
+ /** @param Arg the type of arguments, could be tpd.Tree, untpd.Tree, or Type
* @param methRef the reference to the method of the application
* @param funType the type of the function part of the application
* @param args the arguments of the application
@@ -206,7 +205,7 @@ trait Applications extends Compatibility{ self: Typer =>
args match {
case (arg @ NamedArg(aname, _)) :: args1 =>
if (namedToArg contains aname)
- emptyTree[T]() :: recur(pnames1, args)
+ genericEmptyTree :: recur(pnames1, args)
else {
badNamedArg(arg)
recur(pnames1, args1)
@@ -222,8 +221,7 @@ trait Applications extends Compatibility{ self: Typer =>
val (namedArgs, otherArgs) = args partition isNamedArg
namedArgs foreach badNamedArg
otherArgs
- }
- else args
+ } else args
}
recur(methodType.paramNames, args)
@@ -289,14 +287,14 @@ trait Applications extends Compatibility{ self: Typer =>
}
def tryDefault(n: Int, args1: List[Arg]): Unit = {
- findDefaultGetter(n + TreeInfo.numArgs(normalizedFun)) match {
+ findDefaultGetter(n + numArgs(normalizedFun)) match {
case dref: NamedType =>
liftFun()
addTyped(treeToArg(spliceMeth(Ident(dref), normalizedFun)), formal)
matchArgs(args1, formals1, n + 1)
case _ =>
missingArg(n)
- }
+ }
}
if (formal.isRepeatedParam)
@@ -377,7 +375,7 @@ trait Applications extends Compatibility{ self: Typer =>
*/
trait TreeApplication[T >: Untyped] extends Application[Trees.Tree[T]] {
type TypeArg = Tree
- def isVarArg(arg: Trees.Tree[T]): Boolean = TreeInfo.isWildcardStarArg(arg)
+ def isVarArg(arg: Trees.Tree[T]): Boolean = isWildcardStarArg(arg)
}
/** Subclass of Application for applicability tests with trees as arguments. */
@@ -471,7 +469,7 @@ trait Applications extends Compatibility{ self: Typer =>
typedArgs = args.asInstanceOf[List[Tree]]
methodType.instantiate(typedArgs map (_.tpe))
}
- val app1 = app.withType(ownType).derivedApply(normalizedFun, typedArgs)
+ val app1 = cpy.Apply(app, normalizedFun, typedArgs).withType(ownType)
if (liftedDefs != null && liftedDefs.nonEmpty) Block(liftedDefs.toList, app1)
else app1
}
@@ -495,7 +493,7 @@ trait Applications extends Compatibility{ self: Typer =>
new ApplyToTyped(app, fun, methRef, args, resultType).result
def typedApply(fun: Tree, methRef: TermRef, args: List[Tree], resultType: Type)(implicit ctx: Context): Tree =
- typedApply(Trees.Apply(untpd.TypedSplice(fun), Nil), fun, methRef, args, resultType)
+ typedApply(untpd.Apply(untpd.TypedSplice(fun), Nil), fun, methRef, args, resultType)
def typedApply(tree: untpd.Apply, pt: Type)(implicit ctx: Context): Tree = {
if (ctx.mode is Mode.Pattern)
@@ -505,7 +503,7 @@ trait Applications extends Compatibility{ self: Typer =>
def realApply(implicit ctx: Context) = {
val proto = new FunProtoType(tree.args, pt, this)
val fun1 = typedExpr(tree.fun, proto)
- TreeInfo.methPart(fun1).tpe match {
+ methPart(fun1).tpe match {
case funRef: TermRef =>
val app =
if (proto.argsAreTyped) new ApplyToTyped(tree, fun1, funRef, proto.typedArgs, pt)
@@ -525,12 +523,12 @@ trait Applications extends Compatibility{ self: Typer =>
val lhs1 = typedExpr(lhs)
val lifted = new mutable.ListBuffer[Tree]
val lhs2 = untpd.TypedSplice(liftApp(lifted, lhs1))
- val assign = Trees.Assign(lhs2, Trees.Apply(Trees.Select(lhs2, name.init), rhss))
+ val assign = untpd.Assign(lhs2, untpd.Apply(untpd.Select(lhs2, name.init), rhss))
typed(assign)
}
realApply
- if (TreeInfo.isOpAssign(tree))
+ if (untpd.isOpAssign(tree))
tryEither {
implicit ctx => realApply
} { failed =>
@@ -555,7 +553,7 @@ trait Applications extends Compatibility{ self: Typer =>
ctx.error(s"${err.exprStr(typedFn)} does not take type parameters", tree.pos)
ErrorType
}
- tree.withType(ownType).derivedTypeApply(typedFn, typedArgs)
+ cpy.TypeApply(tree, typedFn, typedArgs).withType(ownType)
}
def typedUnApply(qual: untpd.Tree, args: List[untpd.Tree], tree: untpd.Apply, pt: Type)(implicit ctx: Context): Tree = {
@@ -586,7 +584,7 @@ trait Applications extends Compatibility{ self: Typer =>
ctx.error(s"${unapplyResult.show} is not a valid result type of an unapply method of an extractor", tree.pos)
Nil
}
- }
+ }
recur(unapplyResult)
}
@@ -595,13 +593,14 @@ trait Applications extends Compatibility{ self: Typer =>
val dummyArg = untpd.TypedSplice(dummyTreeOfType(WildcardType))
val unappProto = FunProtoType(dummyArg :: Nil, pt, this)
tryEither {
- implicit ctx => typedExpr(Trees.Select(qual, nme.unapply), unappProto)
+ implicit ctx => typedExpr(untpd.Select(qual, nme.unapply), unappProto)
} {
- s => tryEither {
- implicit ctx => typedExpr(Trees.Select(qual, nme.unapplySeq), unappProto) // for backwards compatibility; will be dropped
- } {
- _ => errorTree(s.value, s"${qual.show} cannot be used as an extractor in a pattern because it lacks an unapply or unapplySeq method")
- }
+ s =>
+ tryEither {
+ implicit ctx => typedExpr(untpd.Select(qual, nme.unapplySeq), unappProto) // for backwards compatibility; will be dropped
+ } {
+ _ => errorTree(s.value, s"${qual.show} cannot be used as an extractor in a pattern because it lacks an unapply or unapplySeq method")
+ }
}
}
fn.tpe.widen match {
@@ -610,7 +609,7 @@ trait Applications extends Compatibility{ self: Typer =>
ownType <:< pt // done for registering the constraints; error message would come later
var argTypes = unapplyArgs(ownType)
val bunchedArgs = argTypes match {
- case argType :: Nil if argType.isRepeatedParam => Trees.SeqLiteral(args) :: Nil
+ case argType :: Nil if argType.isRepeatedParam => untpd.SeqLiteral(args) :: Nil
case _ => args
}
if (argTypes.length != bunchedArgs.length) {
@@ -619,7 +618,7 @@ trait Applications extends Compatibility{ self: Typer =>
List.fill(argTypes.length - args.length)(WildcardType)
}
val typedArgs = (bunchedArgs, argTypes).zipped map (typed(_, _))
- Trees.UnApply(fn, typedArgs).withPos(tree.pos).withType(ownType)
+ untpd.UnApply(fn, typedArgs).withPos(tree.pos).withType(ownType)
case et: ErrorType =>
tree.withType(ErrorType)
}
@@ -713,7 +712,7 @@ trait Applications extends Compatibility{ self: Typer =>
best :: asGood(alts1)
}
- private val dummyTree = Trees.Literal(Constant(null))
+ private val dummyTree = untpd.Literal(Constant(null))
def dummyTreeOfType(tp: Type): Tree = dummyTree withType tp
/** Resolve overloaded alternative `alts`, given expected type `pt`. */
@@ -735,7 +734,7 @@ trait Applications extends Compatibility{ self: Typer =>
def treeShape(tree: untpd.Tree): Tree = tree match {
case NamedArg(name, arg) =>
val argShape = treeShape(arg)
- tree.withType(argShape.tpe).derivedNamedArg(name, argShape)
+ cpy.NamedArg(tree, name, argShape).withType(argShape.tpe)
case _ =>
dummyTreeOfType(typeShape(tree))
}
@@ -783,7 +782,7 @@ trait Applications extends Compatibility{ self: Typer =>
}
case pt @ PolyProtoType(nargs, _) =>
- alts filter ( alt => alt.widen match {
+ alts filter (alt => alt.widen match {
case PolyType(pnames) if pnames.length == nargs => true
case _ => false
})
diff --git a/src/dotty/tools/dotc/typer/EtaExpansion.scala b/src/dotty/tools/dotc/typer/EtaExpansion.scala
index 48b7a063e..6a2b2060e 100644
--- a/src/dotty/tools/dotc/typer/EtaExpansion.scala
+++ b/src/dotty/tools/dotc/typer/EtaExpansion.scala
@@ -21,7 +21,7 @@ object EtaExpansion {
import tpd._
def lift(defs: mutable.ListBuffer[Tree], expr: Tree, prefix: String = "")(implicit ctx: Context): Tree =
- if (TreeInfo.isIdempotentExpr(expr)) expr
+ if (isIdempotentExpr(expr)) expr
else {
val name = ctx.freshName(prefix).toTermName
val sym = ctx.newSymbol(ctx.owner, name, EmptyFlags, expr.tpe, coord = positionCoord(expr.pos))
@@ -46,11 +46,11 @@ object EtaExpansion {
def liftApp(defs: mutable.ListBuffer[Tree], tree: Tree)(implicit ctx: Context): Tree = tree match {
case Apply(fn, args) =>
- tree.derivedApply(liftApp(defs, fn), liftArgs(defs, fn.tpe, args))
+ cpy.Apply(tree, liftApp(defs, fn), liftArgs(defs, fn.tpe, args))
case TypeApply(fn, targs) =>
- tree.derivedTypeApply(liftApp(defs, fn), targs)
+ cpy.TypeApply(tree, liftApp(defs, fn), targs)
case Select(pre, name) =>
- tree.derivedSelect(lift(defs, pre), name)
+ cpy.Select(tree, lift(defs, pre), name)
case Ident(name) =>
lift(defs, tree)
case Block(stats, expr) =>
diff --git a/src/dotty/tools/dotc/typer/Namer.scala b/src/dotty/tools/dotc/typer/Namer.scala
index 1279fcf03..716de5f3c 100644
--- a/src/dotty/tools/dotc/typer/Namer.scala
+++ b/src/dotty/tools/dotc/typer/Namer.scala
@@ -178,8 +178,8 @@ class Namer { typer: Typer =>
case Some(cdef) =>
val Thicket((mcls @ TypeDef(_, _, impl: Template)) :: mrest) = expandedTree(mdef)
val Thicket(cls :: TypeDef(_, _, compimpl: Template) :: crest) = expandedTree(cdef)
- val mcls1 = mcls.derivedTypeDef(mcls.mods, mcls.name,
- impl.derivedTemplate(impl.constr, impl.parents, impl.self,
+ val mcls1 = cpy.TypeDef(mcls, mcls.mods, mcls.name,
+ cpy.Template(impl, impl.constr, impl.parents, impl.self,
compimpl.body ++ impl.body))
expandedTree(mdef) = Thicket(mcls1 :: mrest)
expandedTree(cdef) = Thicket(cls :: crest)
@@ -311,7 +311,7 @@ class Namer { typer: Typer =>
def classDefSig(cdef: TypeDef, cls: ClassSymbol)(implicit ctx: Context): Type = {
def parentType(constr: untpd.Tree): Type = {
- val Trees.Select(Trees.New(tpt), _) = TreeInfo.methPart(constr)
+ val Trees.Select(Trees.New(tpt), _) = methPart(constr)
val ptype = typedAheadType(tpt).tpe
if (ptype.uninstantiatedTypeParams.isEmpty) ptype
else typedAheadExpr(constr).tpe
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala
index 6d6211daf..733eac739 100644
--- a/src/dotty/tools/dotc/typer/Typer.scala
+++ b/src/dotty/tools/dotc/typer/Typer.scala
@@ -31,7 +31,7 @@ trait TyperContextOps { ctx: Context => }
object Typer {
- import tpd._
+ import tpd.{cpy => _, _}
object BindingPrec {
val definition = 4
@@ -59,8 +59,9 @@ object Typer {
class Typer extends Namer with Applications with Implicits {
- import tpd._
import Typer._
+ import tpd.{cpy => _, _}
+ import untpd.cpy
/** A temporary data item valid for a single typed ident:
* The set of all root import symbols that have been
@@ -300,7 +301,7 @@ class Typer extends Namer with Applications with Implicits {
val qual1 = typedExpr(tree.qualifier, RefinedType(WildcardType, tree.name, pt))
val ownType = typedSelection(qual1.exprType, tree.name, tree.pos)
if (!ownType.isError) checkAccessible(ownType, qual1.isInstanceOf[Super], tree.pos)
- tree.withType(ownType).derivedSelect(qual1, tree.name)
+ cpy.Select(tree, qual1, tree.name).withType(ownType)
}
def typedThis(tree: untpd.This)(implicit ctx: Context): Tree = {
@@ -326,7 +327,7 @@ class Typer extends Namer with Applications with Implicits {
else if (ctx.mode is Mode.InSuperInit) cls.info.firstParent
else cls.info.parents.reduceLeft((x: Type, y: Type) => AndType(x, y))
- tree.withType(SuperType(cls.thisType, owntype)).derivedSuper(qual1, mix)
+ cpy.Super(tree, qual1, mix).withType(SuperType(cls.thisType, owntype))
}
def typedLiteral(tree: untpd.Literal)(implicit ctx: Context) =
@@ -336,24 +337,24 @@ class Typer extends Namer with Applications with Implicits {
val tpt1 = typedType(tree.tpt)
val cls = checkClassTypeWithStablePrefix(tpt1.tpe, tpt1.pos)
checkInstantiatable(cls, tpt1.pos)
- tree.withType(tpt1.tpe).derivedNew(tpt1)
+ cpy.New(tree, tpt1).withType(tpt1.tpe)
}
def typedPair(tree: untpd.Pair)(implicit ctx: Context) = {
val left1 = typed(tree.left)
val right1 = typed(tree.right)
- tree.withType(defn.PairType.appliedTo(left1.tpe :: right1.tpe :: Nil)).derivedPair(left1, right1)
+ cpy.Pair(tree, left1, right1).withType(defn.PairType.appliedTo(left1.tpe :: right1.tpe :: Nil))
}
def TypedTyped(tree: untpd.Typed)(implicit ctx: Context) = {
val tpt1 = typedType(tree.tpt)
val expr1 = typedExpr(tree.expr, tpt1.tpe)
- tree.withType(tpt1.tpe).derivedTyped(tpt1, expr1)
+ cpy.Typed(tree, tpt1, expr1).withType(tpt1.tpe)
}
def NamedArg(tree: untpd.NamedArg, pt: Type)(implicit ctx: Context) = {
val arg1 = typed(tree.arg, pt)
- tree.withType(arg1.tpe).derivedNamedArg(tree.name, arg1)
+ cpy.NamedArg(tree, tree.name, arg1).withType(arg1.tpe)
}
def Assign(tree: untpd.Assign)(implicit ctx: Context) = {
@@ -375,7 +376,7 @@ class Typer extends Namer with Applications with Implicits {
val tpt1 = typedType(tpt)
val rhs1 = typedExpr(rhs, tpt1.tpe)
val pt = if (sym.exists) sym.symRef else NoType
- vdef.withType(pt).derivedValDef(mods1, name, tpt1, rhs1)
+ cpy.ValDef(vdef, mods1, name, tpt1, rhs1).withType(pt)
}
def typedDefDef(ddef: untpd.DefDef, sym: Symbol)(implicit ctx: Context) = {
@@ -385,7 +386,7 @@ class Typer extends Namer with Applications with Implicits {
val vparamss1 = vparamss.mapconserve(_ mapconserve (typed(_).asInstanceOf[ValDef]))
val tpt1 = typedType(tpt)
val rhs1 = typedExpr(rhs, tpt1.tpe)
- ddef.withType(sym.symRef).derivedDefDef(mods1, name, tparams1, vparamss1, tpt1, rhs1)
+ cpy.DefDef(ddef, mods1, name, tparams1, vparamss1, tpt1, rhs1).withType(sym.symRef)
//todo: make sure dependent method types do not depend on implicits or by-name params
}
@@ -393,7 +394,7 @@ class Typer extends Namer with Applications with Implicits {
val TypeDef(mods, name, rhs) = tdef
val mods1 = typedModifiers(mods)
val rhs1 = typedType(rhs)
- tdef.withType(sym.symRef).derivedTypeDef(mods1, name, rhs1)
+ cpy.TypeDef(tdef, mods1, name, rhs1).withType(sym.symRef)
}
def typedClassDef(cdef: untpd.TypeDef, cls: ClassSymbol)(implicit ctx: Context) = {
@@ -401,15 +402,15 @@ class Typer extends Namer with Applications with Implicits {
val mods1 = typedModifiers(mods)
val constr1 = typed(constr).asInstanceOf[DefDef]
val parents1 = parents mapconserve (typed(_))
- val self1 = self.withType(NoType).derivedValDef(
- typedModifiers(self.mods), self.name, typedType(self.tpt), EmptyTree)
+ val self1 = cpy.ValDef(self, typedModifiers(self.mods), self.name, typedType(self.tpt), EmptyTree)
+ .withType(NoType)
val localDummy = ctx.newLocalDummy(cls, impl.pos)
val body1 = typedStats(body, localDummy)(inClassContext(cls, self.name))
- val impl1 = impl.withType(localDummy.symRef).derivedTemplate(
- constr1, parents1, self1, body1)
+ val impl1 = cpy.Template(impl, constr1, parents1, self1, body1)
+ .withType(localDummy.symRef)
- cdef.withType(cls.symRef).derivedTypeDef(mods1, name, impl1)
+ cpy.TypeDef(cdef, mods1, name, impl1).withType(cls.symRef)
// todo later: check that
// 1. If class is non-abstract, it is instantiatable:
@@ -422,7 +423,7 @@ class Typer extends Namer with Applications with Implicits {
def typedImport(imp: untpd.Import, sym: Symbol)(implicit ctx: Context): Import = {
val expr1 = typedExpr(imp.expr)
- imp.withType(sym.symRef).derivedImport(expr1, imp.selectors)
+ cpy.Import(imp, expr1, imp.selectors).withType(sym.symRef)
}
def typedExpanded(tree: untpd.Tree, pt: Type = WildcardType)(implicit ctx: Context): Tree = {
@@ -509,7 +510,7 @@ class Typer extends Namer with Applications with Implicits {
def tryInsertApply(tree: Tree, pt: Type)(fallBack: StateFul[Tree] => Tree)(implicit ctx: Context): Tree =
tryEither {
- implicit ctx => typedSelect(Trees.Select(untpd.TypedSplice(tree), nme.apply), pt)
+ implicit ctx => typedSelect(untpd.Select(untpd.TypedSplice(tree), nme.apply), pt)
} {
fallBack
}
@@ -582,7 +583,7 @@ class Typer extends Namer with Applications with Implicits {
def adaptToArgs(tp: Type, pt: FunProtoType) = tp match {
case _: MethodType => tree
case _ => tryInsertApply(tree, pt) {
- def fn = err.refStr(TreeInfo.methPart(tree).tpe)
+ def fn = err.refStr(methPart(tree).tpe)
val more = tree match {
case Apply(_, _) => " more"
case _ => ""