aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/typer/Typer.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2013-06-05 17:27:02 +0200
committerMartin Odersky <odersky@gmail.com>2013-06-05 17:27:02 +0200
commit898fe8a499c97fa62840e2c79755fc729015a442 (patch)
tree95d0795c01764326bf51f2a0d4c8212b484e5da5 /src/dotty/tools/dotc/typer/Typer.scala
parentb28c9ef75e274bdc54e9502e56c95b505495de5b (diff)
downloaddotty-898fe8a499c97fa62840e2c79755fc729015a442.tar.gz
dotty-898fe8a499c97fa62840e2c79755fc729015a442.tar.bz2
dotty-898fe8a499c97fa62840e2c79755fc729015a442.zip
wip - partial redesign of namer/typer
Diffstat (limited to 'src/dotty/tools/dotc/typer/Typer.scala')
-rw-r--r--src/dotty/tools/dotc/typer/Typer.scala126
1 files changed, 66 insertions, 60 deletions
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala
index ee221f9f2..dd46a678e 100644
--- a/src/dotty/tools/dotc/typer/Typer.scala
+++ b/src/dotty/tools/dotc/typer/Typer.scala
@@ -10,6 +10,7 @@ import util.Positions._
import util.SourcePosition
import collection.mutable
import language.implicitConversions
+import desugar.Mode
trait TyperContextOps { ctx: Context => }
@@ -18,83 +19,88 @@ class Typer extends Namer {
import tpd._
- def typed(tree: untpd.Tree, pt: Type = WildcardType)(implicit ctx: Context): Tree = ???
- def typedExpr(tree: untpd.Tree, pt: Type = WildcardType)(implicit ctx: Context): Tree = ???
- def typedType(tree: untpd.Tree, pt: Type = WildcardType)(implicit ctx: Context): Tree = ???
+ def typedImport(imp: untpd.Import, pt: Type)(implicit ctx: Context): Import = {
+ val expr1 = typed(imp.expr)
+ imp.withType(pt).derivedImport(expr1, imp.selectors)
+ }
- type DefTyper[UT <: untpd.NameTree, T <: tpd.Tree] = (UT, NamedType) => Context => T
+ def typedModifiers(mods: untpd.Modifiers): Modifiers = ???
- def lateDef[UT <: untpd.NameTree, T <: tpd.Tree](defn: UT, op: DefTyper[UT, T])(implicit ctx: Context): T = {
- val sym = symOfUntypedTree(defn)
- sym.ensureCompleted()
- untypedTreeOfSym -= sym
- typedTreeOfSym remove sym match {
- case Some(tree) => tree.asInstanceOf[T]
- case None => op(defn, sym.symRef)(ctx)
- }
+ def typedValDef(defn: untpd.ValDef, sym: Symbol)(implicit ctx: Context) = {
+ val Trees.ValDef(mods, name, tpt, rhs) = defn
+ val mods1 = typedModifiers(mods)
+ val tpt1 = typedType(tpt)
+ val rhs1 = typedExpr(rhs, tpt1.tpe)
+ val pt = if (sym.exists) sym.symRef else NoType
+ defn.withType(pt).derivedValDef(mods1, name, tpt1, rhs1)
}
- def aheadDef[UT <: untpd.NameTree, T <: tpd.Tree](defn: UT, op: DefTyper[UT, T])(implicit ctx: Context): T = {
- val sym = symOfUntypedTree(defn)
- val tree1 = op(defn, sym.symRef)(ctx)
- typedTreeOfSym(sym) = tree1
- tree1
+ def typedDefDef(defn: untpd.DefDef, sym: Symbol)(implicit ctx: Context) = {
+ val Trees.DefDef(mods, name, tparams, vparamss, tpt, rhs) = defn
+ val mods1 = typedModifiers(mods)
+ val tparams1 = tparams mapconserve (typed(_).asInstanceOf[TypeDef])
+ val vparamss1 = vparamss.mapconserve(_ mapconserve (typed(_).asInstanceOf[ValDef]))
+ val tpt1 = typedType(tpt)
+ val rhs1 = typedExpr(rhs, tpt1.tpe)
+ defn.withType(sym.symRef).derivedDefDef(mods1, name, tparams1, vparamss1, tpt1, rhs1)
}
- def noDefTyper: DefTyper[untpd.NameTree, Nothing] = { (tdef, pt) => implicit ctx => ??? }
-
- val completeTypeDef: DefTyper[untpd.TypeDef, TypeDef] = { (tdef, pt) => implicit ctx =>
- val Trees.TypeDef(mods, name, tparams, rhs) = tdef
+ def typedTypeDef(defn: untpd.TypeDef, sym: Symbol)(implicit ctx: Context): TypeDef = {
+ val Trees.TypeDef(mods, name, tparams, rhs) = defn
val mods1 = typedModifiers(mods)
- val tparams1 = reEnterParams(tparams)
+ val tparams1 = tparams mapconserve (typed(_).asInstanceOf[TypeDef])
val rhs1 = typedType(rhs)
- tdef.withType(pt).derivedTypeDef(mods1, name, tparams1, rhs1)
- }
-
- def typedTypedDef(tdef: untpd.TypeDef)(implicit ctx: Context): TypeDef =
- lateDef(tdef, completeTypeDef)
-
- def typedTptRhs(tpt: untpd.Tree, rhs: untpd.Tree)(implicit ctx: Context): (Tree, Tree) = {
- var tpt1: Tree = EmptyTree
- var rhs1: Tree = EmptyTree
- if (tpt.isEmpty) {
- rhs1 = typedExpr(rhs)
- tpt1 = tpt.withType(rhs1.tpe)
- } else {
- tpt1 = typedType(tpt)
- rhs1 = typedExpr(rhs, tpt1.tpe)
- }
- (tpt1, rhs1)
+ defn.withType(sym.symRef).derivedTypeDef(mods1, name, tparams1, rhs1)
}
- val completeValDef: DefTyper[untpd.ValDef, ValDef] = { (vdef, pt) => implicit ctx: Context =>
- val Trees.ValDef(mods, name, tpt, rhs) = vdef
+ def typedClassDef(defn: untpd.ClassDef, cls: ClassSymbol)(implicit ctx: Context) = {
+ val Trees.ClassDef(mods, name, impl @ Trees.Template(constr, parents, self, body)) = defn
val mods1 = typedModifiers(mods)
- val (tpt1, rhs1) = typedTptRhs(tpt, rhs)
- vdef.withType(tpt1.tpe).derivedValDef(mods1, name, tpt1, rhs1)
+ val constr1 = typed(constr)
+ val parents1 = parents mapconserve (typed(_))
+ val self1 = typed(self)
+ ???
}
- def reEnterParams[UT <: untpd.NameTree, T <: tpd.Tree](params: List[UT])(implicit ctx: Context): List[T] = {
- for (param <- params) yield {
- val sym = symOfUntypedTree(param)
- ctx.enter(sym)
- lateDef(param, noDefTyper)
+ def typedMemberDef(defn: untpd.MemberDef, sym: Symbol)(implicit ctx: Context) = {
+ sym.ensureCompleted()
+ def localContext = ctx.fresh.withOwner(sym)
+ defn match {
+ case defn: untpd.ValDef =>
+ typedValDef(defn, sym)(localContext)
+ case defn: untpd.DefDef =>
+ val typer1 = nestedTyper.remove(sym).get
+ typer1.typedDefDef(defn, sym)(localContext.withScope(typer1.scope))
+ case defn: untpd.TypeDef =>
+ typedTypeDef(defn, sym)(localContext.withNewScope)
+ case defn: untpd.ClassDef =>
+ typedClassDef(defn, sym.asClass)(localContext)
}
}
- val completeDefDef: DefTyper[untpd.DefDef, DefDef] = { (ddef, pt) => implicit ctx: Context =>
- val Trees.DefDef(mods, name, tparams, vparamss, tpt, rhs) = ddef
- val mods1 = typedModifiers(mods)
- val tparams1: List[TypeDef] = reEnterParams(tparams)
- val vparamss1: List[List[ValDef]] = vparamss.mapconserve(reEnterParams)
- val (tpt1, rhs1) = typedTptRhs(tpt, rhs)
- ddef.withType(tpt1.tpe).derivedDefDef(mods1, name, tparams1, vparamss1, tpt1, rhs1)
+ def typed(tree: untpd.Tree, mode: Mode.Value = Mode.Expr, pt: Type = WildcardType)(implicit ctx: Context): Tree = {
+ typedTree get tree match {
+ case Some(tree1) => tree1
+ case none => tree match {
+ case defn: untpd.MemberDef =>
+ typedMemberDef(defn, symOfTree(defn))
+ case imp: untpd.Import =>
+ typedImport(imp, symOfTree(imp).symRef)
+ case tree: untpd.TypeTree =>
+ if (!tree.isEmpty) typed(tree.original, Mode.Type, pt)
+ else {
+ assert(pt != WildcardType)
+ tree.withType(pt)
+ }
+ case untpd.EmptyTree =>
+ tpd.EmptyTree
+ }
+ }
}
- def typedImport(imp: untpd.Import, pt: Type)(implicit ctx: Context): Import = {
- val expr1 = typed(imp.expr)
- imp.withType(pt).derivedImport(expr1, imp.selectors)
- }
+ def typedExpr(tree: untpd.Tree, pt: Type = WildcardType)(implicit ctx: Context): Tree =
+ typed(tree, Mode.Expr, pt)
+ def typedType(tree: untpd.Tree, pt: Type = WildcardType)(implicit ctx: Context): Tree =
+ typed(tree, Mode.Type, pt)
- def typedModifiers(mods: untpd.Modifiers): Modifiers = ???
} \ No newline at end of file