aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2013-04-23 17:04:34 +0200
committerMartin Odersky <odersky@gmail.com>2013-04-23 17:04:34 +0200
commitfc8fc177d2dfd270e57996099deef2e4a3a975ed (patch)
treec4c143f88249c6a40a9f1e4c886260d26267b75e /src/dotty/tools/dotc/core
parent8566b093c35d5cc5b29544b5b2c3f01b0ec4c1bd (diff)
downloaddotty-fc8fc177d2dfd270e57996099deef2e4a3a975ed.tar.gz
dotty-fc8fc177d2dfd270e57996099deef2e4a3a975ed.tar.bz2
dotty-fc8fc177d2dfd270e57996099deef2e4a3a975ed.zip
Modifications in prepation of parsing.
Diffstat (limited to 'src/dotty/tools/dotc/core')
-rw-r--r--src/dotty/tools/dotc/core/Contexts.scala1
-rw-r--r--src/dotty/tools/dotc/core/Flags.scala4
-rw-r--r--src/dotty/tools/dotc/core/StdNames.scala2
-rw-r--r--src/dotty/tools/dotc/core/TreeInfo.scala10
-rw-r--r--src/dotty/tools/dotc/core/Trees.scala172
-rw-r--r--src/dotty/tools/dotc/core/TypedTrees.scala11
-rw-r--r--src/dotty/tools/dotc/core/UntypedTrees.scala21
7 files changed, 173 insertions, 48 deletions
diff --git a/src/dotty/tools/dotc/core/Contexts.scala b/src/dotty/tools/dotc/core/Contexts.scala
index 2838f1c7f..6e089dde6 100644
--- a/src/dotty/tools/dotc/core/Contexts.scala
+++ b/src/dotty/tools/dotc/core/Contexts.scala
@@ -294,6 +294,7 @@ object Contexts {
def freshName(): String = freshNames.newName()
def freshName(prefix: String): String = freshNames.newName(prefix)
+ def freshName(prefix: Name): String = freshName(prefix.toString)
/** The loader that loads the members of _root_ */
def rootLoader(root: TermSymbol)(implicit ctx: Context): SymbolLoader = platform.rootLoader(root)
diff --git a/src/dotty/tools/dotc/core/Flags.scala b/src/dotty/tools/dotc/core/Flags.scala
index 4e88515e9..df4d873a5 100644
--- a/src/dotty/tools/dotc/core/Flags.scala
+++ b/src/dotty/tools/dotc/core/Flags.scala
@@ -84,6 +84,9 @@ object Flags {
/** The number of non-kind flags in this set */
def numFlags: Int = java.lang.Long.bitCount(bits & ~KINDFLAGS)
+ /** The lowest non-kind bit set in this flagset */
+ def firstBit: Int = java.lang.Long.numberOfTrailingZeros(bits & ~KINDFLAGS)
+
/** The list of non-empty names of flags with given index idx that are set in this FlagSet */
private def flagString(idx: Int): List[String] =
if ((bits & (1L << idx)) == 0) Nil
@@ -444,6 +447,7 @@ object Flags {
final val SyntheticTermParam = allOf(Synthetic, TermParam)
final val SyntheticTypeParam = allOf(Synthetic, TypeParam)
final val SyntheticCase = allOf(Synthetic, Case)
+ final val AbstractAndOverride = allOf(Abstract, Override)
implicit def conjToFlagSet(conj: FlagConjunction): FlagSet =
FlagSet(conj.bits)
diff --git a/src/dotty/tools/dotc/core/StdNames.scala b/src/dotty/tools/dotc/core/StdNames.scala
index 4ef3456df..80d3ac6b6 100644
--- a/src/dotty/tools/dotc/core/StdNames.scala
+++ b/src/dotty/tools/dotc/core/StdNames.scala
@@ -290,6 +290,7 @@ object StdNames {
val NoPrefix: N = "NoPrefix"
val NoSymbol: N = "NoSymbol"
val NoType: N = "NoType"
+ val Pair: N = "Pair"
val Ref: N = "Ref"
val RootPackage: N = "RootPackage"
val RootClass: N = "RootClass"
@@ -540,6 +541,7 @@ object StdNames {
val ZOR = encode("||")
// unary operators
+ val UNARY_PREFIX: N = "unary_"
val UNARY_~ = encode("unary_~")
val UNARY_+ = encode("unary_+")
val UNARY_- = encode("unary_-")
diff --git a/src/dotty/tools/dotc/core/TreeInfo.scala b/src/dotty/tools/dotc/core/TreeInfo.scala
index cb621164c..c3d0d4ece 100644
--- a/src/dotty/tools/dotc/core/TreeInfo.scala
+++ b/src/dotty/tools/dotc/core/TreeInfo.scala
@@ -16,7 +16,7 @@ abstract class TreeInfo {
def isDeclarationOrTypeDef(tree: Tree[_ >: Untyped]): Boolean = tree match {
case DefDef(_, _, _, _, _, EmptyTree())
| ValDef(_, _, _, EmptyTree())
- | TypeDef(_, _, _) => true
+ | TypeDef(_, _, _, _) => true
case _ => false
}
@@ -25,7 +25,7 @@ abstract class TreeInfo {
def isInterfaceMember(tree: Tree[_ >: Untyped]): Boolean = tree match {
case EmptyTree() => true
case Import(_, _) => true
- case TypeDef(_, _, _) => true
+ case TypeDef(_, _, _, _) => true
case DefDef(mods, _, _, _, _, __) => mods.flags is Deferred
case ValDef(mods, _, _, _) => mods is Deferred
case _ => false
@@ -37,7 +37,7 @@ abstract class TreeInfo {
def isIdempotentDef(tree: Tree[Type])(implicit ctx: Context): Boolean = tree match {
case EmptyTree()
| ClassDef(_, _, _, _)
- | TypeDef(_, _, _)
+ | TypeDef(_, _, _, _)
| Import(_, _)
| DefDef(_, _, _, _, _, _) =>
true
@@ -231,7 +231,7 @@ abstract class TreeInfo {
}
def isEarlyTypeDef(tree: Tree[_ >: Untyped]) = tree match {
- case TypeDef(mods, _, _) => mods is Scala2PreSuper
+ case TypeDef(mods, _, _, _) => mods is Scala2PreSuper
case _ => false
}
@@ -476,4 +476,4 @@ abstract class TreeInfo {
case _ => false
})*/
}
-object treeInfo extends TreeInfo \ No newline at end of file
+object TreeInfo extends TreeInfo \ No newline at end of file
diff --git a/src/dotty/tools/dotc/core/Trees.scala b/src/dotty/tools/dotc/core/Trees.scala
index 7befc9956..07a6ada69 100644
--- a/src/dotty/tools/dotc/core/Trees.scala
+++ b/src/dotty/tools/dotc/core/Trees.scala
@@ -6,6 +6,7 @@ import Denotations._, StdNames._
import annotation.tailrec
import language.higherKinds
import collection.mutable
+import collection.mutable.ArrayBuffer
object Trees {
@@ -19,22 +20,87 @@ object Trees {
type TypedTree = Tree[Type]
type UntypedTree = Tree[Untyped]
+ /** Modifiers and annotations for definitions
+ * @param flags The set flags
+ * @param privateWithin If a private or protected has is followed by a
+ * qualifier [q], the name q, "" as a typename otherwise.
+ * @param annotations The annotations preceding the modifers
+ * @param positions A flagPositions structure that records the positions
+ * of et flags.
+ * @param pos The position of the modifiers. This should start with
+ * the first modifier or annotation and have as point
+ * the start of the opening keyword(s) of the definition.
+ * It should have as end the end of the opening keywords(s).
+ */
case class Modifiers[T >: Untyped](
flags: FlagSet = EmptyFlags,
privateWithin: TypeName = tpnme.EMPTY,
- annotations: List[Tree[T]] = Nil) {
+ annotations: List[Tree[T]] = Nil,
+ positions: FlagPositions = NoFlagPositions)(implicit val cpos: Position = NoPosition) {
+
+ def | (fs: FlagSet): Modifiers[T] = copy(flags = flags | fs)(cpos)
+ def & (fs: FlagSet): Modifiers[T] = copy(flags = flags & fs)(cpos)
+ def &~(fs: FlagSet): Modifiers[T] = copy(flags = flags &~ fs)(cpos)
+
+ def is(fs: FlagSet): Boolean = flags is fs
+ def is(fc: FlagConjunction): Boolean = flags is fc
+
+ def add(flag: FlagSet, start: Int) =
+ copy(flags = flags | flag, positions = positions.add(flag, start))
+
+ def withAnnotations(annots: List[Tree[T]]) =
+ if (annots.isEmpty) this
+ else copy(annotations = annotations ++ annots)(cpos)
+
+ def withPrivateWithin(pw: TypeName) =
+ if (pw.isEmpty) this
+ else copy(privateWithin = pw)(cpos)
+
+ def withPos(pos: Position) = copy()(pos)
- def | (fs: FlagSet) = copy(flags = flags | fs)
- def & (fs: FlagSet) = copy(flags = flags & fs)
- def &~(fs: FlagSet) = copy(flags = flags &~ fs)
- def is(fs: FlagSet) = flags is fs
- def is(fc: FlagConjunction) = flags is fc
+ val pos: Position = unionPos(cpos, annotations)
}
- private val modCache = mutable.Map[FlagSet, Modifiers[Untyped]]()
+ private final val OffsetShift = 6
+ private final val FlagMask = (1 << OffsetShift) - 1
- def apply[T >: Untyped](flags: FlagSet = EmptyFlags): Modifiers[T] =
- modCache.getOrElseUpdate(flags, Modifiers(flags, tpnme.EMPTY, Nil)).asInstanceOf[Modifiers[T]]
+ class FlagPositions(val arr: Array[Int]) extends AnyVal {
+ def get(flag: FlagSet): Position = {
+ val str :: Nil = flag.flagStrings.toList
+ val code = flag.firstBit
+ var i = 0
+ while (i < arr.length && ((arr(i) & FlagMask) != code)) i += 1
+ if (i < arr.length) {
+ val start = arr(i) >>> OffsetShift
+ val end = start + str.length
+ Position(start, end)
+ } else
+ NoPosition
+ }
+ def add(flag: FlagSet, start: Int) = {
+ val newarr = new Array[Int](arr.length + 1)
+ arr.copyToArray(newarr)
+ setFlagPosition(newarr, arr.length, flag, start)
+ new FlagPositions(newarr)
+ }
+ }
+
+ private def setFlagPosition(arr: Array[Int], idx: Int, flag: FlagSet, start: Int): Unit = {
+ val code = flag.firstBit
+ assert(code <= 64)
+ arr(idx) = code | (start << OffsetShift)
+ }
+
+ def FlagPositions(assocs: ArrayBuffer[(FlagSet, Int)]): FlagPositions = {
+ val arr = Array[Int](assocs.size)
+ for (i <- 0 until assocs.size) {
+ val (flag, start) = assocs(i)
+ setFlagPosition(arr, i, flag, start)
+ }
+ FlagPositions(assocs)
+ }
+
+ val NoFlagPositions = new FlagPositions(Array())
/** Trees take a parameter indicating what the type of their `tpe` field
* is. Two choices: `Type` or `Untyped`.
@@ -56,10 +122,14 @@ object Trees {
/** The tree's position. Except
* for SharedTree nodes, it is always ensured that a tree's position
- * contains the positions of all its subtrees.
+ * contains the positions of all its immediate subtrees. However, it need not
+ * contain positions of other tree elements such as Modifiers.
*/
def pos: Position
+ /** The extended position. Unlike `pos`, this one contains positions of modifiers */
+ def xpos: Position = pos
+
/** The type constructor at the root of the tree */
type ThisTree[T >: Untyped] <: Tree[T]
@@ -129,6 +199,10 @@ object Trees {
/** Is this tree either the empty tree or the empty ValDef? */
def isEmpty: Boolean = false
+ /** if this tree is the empty tree, the alternative, else this tree */
+ def orElse(that: => Tree[T]): Tree[T] =
+ if (this eq theEmptyTree) that else this
+
override def toText(implicit ctx: Context) = ctx.toText(this)
override def hashCode(): Int = System.identityHashCode(this)
@@ -205,6 +279,19 @@ object Trees {
override def isDef = true
}
+ /** Tree defines a new symbol and carries modifiers.
+ * The position of a ModDefTree usually starts
+ * at the symbol that's being defined (known exception:
+ * A type definition starts at the +/- if there is one).
+ * The annotations, modifiers and keyword that come before
+ * are subsumed in the modifier position.
+ */
+ trait ModDefTree[T >: Untyped] extends DefTree[T] {
+ type ThisTree[T >: Untyped] <: ModDefTree[T]
+ def mods: Modifiers[T]
+ override def xpos = mods.pos union pos
+ }
+
// ----------- Tree case classes ------------------------------------
/** name */
@@ -275,8 +362,16 @@ object Trees {
val pos = cpos union tpt.pos
}
- def New[T >: Untyped](tpt: Tree[T], argss: List[List[Tree[T]]])(implicit cpos: Position): Tree[T] =
- ((Select(New(tpt), nme.CONSTRUCTOR): Tree[T]) /: argss)(Apply(_, _))
+ /** new tpt(args1)...(args_n)
+ * @param cpos A position spanning the new.
+ */
+ def New[T >: Untyped](tpt: Tree[T], argss: List[List[Tree[T]]])(implicit cpos: Position): Tree[T] = {
+ val newPos = cpos.withEnd(tpt.pos.end min cpos.end)
+ locally {
+ implicit val cpos: Position = newPos
+ ((Select(New(tpt), nme.CONSTRUCTOR): Tree[T]) /: argss)(Apply(_, _))
+ }
+ }
/** (left, right) */
case class Pair[T >: Untyped](left: Tree[T], right: Tree[T])(implicit cpos: Position)
@@ -343,7 +438,7 @@ object Trees {
* After program transformations this is not necessarily the enclosing method, because
* closures can intervene.
*/
- case class Return[T >: Untyped](expr: Tree[T], from: Ident[T])(implicit cpos: Position)
+ case class Return[T >: Untyped](expr: Tree[T], from: Tree[T] = EmptyTree[T]())(implicit cpos: Position)
extends TermTree[T] {
type ThisTree[T >: Untyped] = Return[T]
val pos = cpos union expr.pos // from is synthetic, does not influence pos
@@ -406,7 +501,7 @@ object Trees {
}
/** tpt { refinements } */
- case class RefineTypeTree[T >: Untyped](tpt: Tree[T], refinements: List[DefTree[T]])(implicit cpos: Position)
+ case class RefineTypeTree[T >: Untyped](tpt: Tree[T], refinements: List[Tree[T]])(implicit cpos: Position)
extends ProxyTree[T] with TypTree[T] {
type ThisTree[T >: Untyped] = RefineTypeTree[T]
val pos = unionPos(cpos union tpt.pos, refinements)
@@ -421,6 +516,9 @@ object Trees {
def forwardTo = tpt
}
+ def AppliedTypeTree[T >: Untyped](tpt: Tree[T], arg: Tree[T])(implicit cpos: Position): AppliedTypeTree[T] =
+ AppliedTypeTree(tpt, arg :: Nil)
+
/** >: lo <: hi */
case class TypeBoundsTree[T >: Untyped](lo: Tree[T], hi: Tree[T])(implicit cpos: Position)
extends Tree[T] {
@@ -451,14 +549,14 @@ object Trees {
/** mods val name: tpt = rhs */
case class ValDef[T >: Untyped](mods: Modifiers[T], name: TermName, tpt: Tree[T], rhs: Tree[T])(implicit cpos: Position)
- extends NameTree[T] with DefTree[T] {
+ extends NameTree[T] with ModDefTree[T] {
type ThisTree[T >: Untyped] = ValDef[T]
val pos = cpos union tpt.pos union rhs.pos
}
/** mods def name[tparams](vparams_1)...(vparams_n): tpt = rhs */
case class DefDef[T >: Untyped](mods: Modifiers[T], name: TermName, tparams: List[TypeDef[T]], vparamss: List[List[ValDef[T]]], tpt: Tree[T], rhs: Tree[T])(implicit cpos: Position)
- extends NameTree[T] with DefTree[T] {
+ extends NameTree[T] with ModDefTree[T] {
type ThisTree[T >: Untyped] = DefDef[T]
val pos = (unionPos(cpos union tpt.pos union rhs.pos, tparams) /: vparamss)(unionPos)
}
@@ -471,22 +569,22 @@ object Trees {
/** mods type name = rhs or
* mods type name >: lo <: hi, if rhs = TypeBoundsTree(lo, hi)
*/
- case class TypeDef[T >: Untyped](mods: Modifiers[T], name: TypeName, rhs: Tree[T])(implicit cpos: Position)
- extends NameTree[T] with DefTree[T] {
+ case class TypeDef[T >: Untyped](mods: Modifiers[T], name: TypeName, tparams: List[TypeDef[T]], rhs: Tree[T])(implicit cpos: Position)
+ extends NameTree[T] with ModDefTree[T] {
type ThisTree[T >: Untyped] = TypeDef[T]
- val pos = cpos union rhs.pos
+ val pos = unionPos(cpos union rhs.pos, tparams)
}
/** extends parents { self => body } */
case class Template[T >: Untyped](parents: List[Tree[T]], self: ValDef[T], body: List[Tree[T]])(implicit cpos: Position)
extends DefTree[T] {
type ThisTree[T >: Untyped] = Template[T]
- val pos = unionPos(unionPos(cpos union self.pos, parents), body)
+ val pos = unionPos(unionPos(cpos union self.xpos, parents), body)
}
/** mods class name[tparams] impl */
case class ClassDef[T >: Untyped](mods: Modifiers[T], name: TypeName, tparams: List[TypeDef[T]], impl: Template[T])(implicit cpos: Position)
- extends NameTree[T] with DefTree[T] {
+ extends NameTree[T] with ModDefTree[T] {
type ThisTree[T >: Untyped] = ClassDef[T]
val pos = unionPos(cpos union impl.pos, tparams)
}
@@ -537,7 +635,7 @@ object Trees {
}
class EmptyValDef[T >: Untyped] extends ValDef[T](
- Modifiers[T](Private), nme.WILDCARD, EmptyTree[T], EmptyTree[T])(NoPosition) with AlwaysEmpty[T]
+ Modifiers[T](Private)(NoPosition), nme.WILDCARD, EmptyTree[T], EmptyTree[T])(NoPosition) with AlwaysEmpty[T]
private object theEmptyValDef extends EmptyValDef[Untyped]
@@ -564,8 +662,8 @@ object Trees {
/** mods object name impl */
case class ModuleDef(mods: Modifiers[Untyped], name: TermName, impl: Template[Untyped])(implicit cpos: Position)
- extends NameTree[Untyped] with DefTree[Untyped] {
- type ThisTree[T >: Untyped] <: NameTree[T] with DefTree[T] with ModuleDef
+ extends NameTree[Untyped] with ModDefTree[Untyped] {
+ type ThisTree[T >: Untyped] <: NameTree[T] with ModDefTree[T] with ModuleDef
val pos = cpos union impl.pos
def derivedModuleDef(mods: Modifiers[Untyped], name: TermName, impl: Template[Untyped]) =
if (mods == this.mods && name == this.name && (impl eq this.impl)) this
@@ -665,7 +763,7 @@ object Trees {
// ----- Helper functions and classes ---------------------------------------
@tailrec final def unionPos(base: Position, trees: List[Tree[_]]): Position = trees match {
- case t :: ts => unionPos(base union t.pos, ts)
+ case t :: ts => unionPos(base union t.xpos, ts)
case nil => base
}
@@ -738,7 +836,7 @@ object Trees {
case tree: CaseDef[_] if (pat eq tree.pat) && (guard eq tree.guard) && (body eq tree.body) => tree
case _ => CaseDef(pat, guard, body).copyAttr(tree)
}
- def derivedReturn(expr: Tree[T], from: Ident[T]): Return[T] = tree match {
+ def derivedReturn(expr: Tree[T], from: Tree[T]): Return[T] = tree match {
case tree: Return[_] if (expr eq tree.expr) && (from eq tree.from) => tree
case _ => Return(expr, from).copyAttr(tree)
}
@@ -774,7 +872,7 @@ object Trees {
case tree: OrTypeTree[_] if (left eq tree.left) && (right eq tree.right) => tree
case _ => OrTypeTree(left, right).copyAttr(tree)
}
- def derivedRefineTypeTree(tpt: Tree[T], refinements: List[DefTree[T]]): RefineTypeTree[T] = tree match {
+ def derivedRefineTypeTree(tpt: Tree[T], refinements: List[Tree[T]]): RefineTypeTree[T] = tree match {
case tree: RefineTypeTree[_] if (tpt eq tree.tpt) && (refinements eq tree.refinements) => tree
case _ => RefineTypeTree(tpt, refinements).copyAttr(tree)
}
@@ -806,9 +904,9 @@ object Trees {
case tree: DefDef[_] if (mods == tree.mods) && (name == tree.name) && (tparams eq tree.tparams) && (vparamss eq tree.vparamss) && (tpt eq tree.tpt) && (rhs eq tree.rhs) => tree
case _ => DefDef(mods, name, tparams, vparamss, tpt, rhs).copyAttr(tree)
}
- def derivedTypeDef(mods: Modifiers[T], name: TypeName, rhs: Tree[T]): TypeDef[T] = tree match {
- case tree: TypeDef[_] if (mods == tree.mods) && (name == tree.name) && (rhs eq tree.rhs) => tree
- case _ => TypeDef(mods, name, rhs).copyAttr(tree)
+ def derivedTypeDef(mods: Modifiers[T], name: TypeName, tparams: List[TypeDef[T]], rhs: Tree[T]): TypeDef[T] = tree match {
+ case tree: TypeDef[_] if (mods == tree.mods) && (name == tree.name) && (tparams eq tree.tparams) && (rhs eq tree.rhs) => tree
+ case _ => TypeDef(mods, name, tparams, rhs).copyAttr(tree)
}
def derivedTemplate(parents: List[Tree[T]], self: ValDef[T], body: List[Tree[T]]): Template[T] = tree match {
case tree: Template[_] if (parents eq tree.parents) && (self eq tree.self) && (body eq tree.body) => tree
@@ -873,7 +971,7 @@ object Trees {
case CaseDef(pat, guard, body) =>
finishCaseDef(tree.derivedCaseDef(transform(pat, c), transform(guard, c), transform(body, c)), tree, c, plugins)
case Return(expr, from) =>
- finishReturn(tree.derivedReturn(transform(expr, c), transformSub(from, c)), tree, c, plugins)
+ finishReturn(tree.derivedReturn(transform(expr, c), transform(from, c)), tree, c, plugins)
case Try(block, catches, finalizer) =>
finishTry(tree.derivedTry(transform(block, c), transformSub(catches, c), transform(finalizer, c)), tree, c, plugins)
case Throw(expr) =>
@@ -906,8 +1004,8 @@ object Trees {
finishValDef(tree.derivedValDef(mods, name, transform(tpt, c), transform(rhs, c)), tree, c, plugins)
case DefDef(mods, name, tparams, vparamss, tpt, rhs) =>
finishDefDef(tree.derivedDefDef(mods, name, transformSub(tparams, c), vparamss mapConserve (transformSub(_, c)), transform(tpt, c), transform(rhs, c)), tree, c, plugins)
- case TypeDef(mods, name, rhs) =>
- finishTypeDef(tree.derivedTypeDef(mods, name, transform(rhs, c)), tree, c, plugins)
+ case TypeDef(mods, name, tparams, rhs) =>
+ finishTypeDef(tree.derivedTypeDef(mods, name, transformSub(tparams, c), transform(rhs, c)), tree, c, plugins)
case Template(parents, self, body) =>
finishTemplate(tree.derivedTemplate(transform(parents, c), transformSub(self, c), transform(body, c)), tree, c, plugins)
case ClassDef(mods, name, tparams, impl) =>
@@ -1055,8 +1153,8 @@ object Trees {
tree.derivedValDef(mods, name, transform(tpt), transform(rhs))
case DefDef(mods, name, tparams, vparamss, tpt, rhs) =>
tree.derivedDefDef(mods, name, transformSub(tparams), vparamss mapConserve (transformSub(_)), transform(tpt), transform(rhs))
- case TypeDef(mods, name, rhs) =>
- tree.derivedTypeDef(mods, name, transform(rhs))
+ case TypeDef(mods, name, tparams, rhs) =>
+ tree.derivedTypeDef(mods, name, transformSub(tparams), transform(rhs))
case Template(parents, self, body) =>
tree.derivedTemplate(transform(parents), transformSub(self), transform(body))
case ClassDef(mods, name, tparams, impl) =>
@@ -1157,8 +1255,8 @@ object Trees {
this(this(x, tpt), rhs)
case DefDef(mods, name, tparams, vparamss, tpt, rhs) =>
this(this((this(x, tparams) /: vparamss)(apply), tpt), rhs)
- case TypeDef(mods, name, rhs) =>
- this(x, rhs)
+ case TypeDef(mods, name, tparams, rhs) =>
+ this(this(x, tparams), rhs)
case Template(parents, self, body) =>
this(this(this(x, parents), self), body)
case ClassDef(mods, name, tparams, impl) =>
diff --git a/src/dotty/tools/dotc/core/TypedTrees.scala b/src/dotty/tools/dotc/core/TypedTrees.scala
index bfe2c957d..348b2c37b 100644
--- a/src/dotty/tools/dotc/core/TypedTrees.scala
+++ b/src/dotty/tools/dotc/core/TypedTrees.scala
@@ -186,7 +186,7 @@ object TypedTrees {
}
def TypeDef(sym: TypeSymbol)(implicit ctx: Context): TypeDef =
- Trees.TypeDef(Modifiers(sym), sym.name, TypeTree(sym.info))(defPos(sym))
+ Trees.TypeDef(Modifiers(sym), sym.name, Nil, TypeTree(sym.info))(defPos(sym)) // !!! fill in typeParams
.withType(refType(sym)).checked
def ClassDef(cls: ClassSymbol, typeParams: List[TypeSymbol], body: List[Tree])(implicit ctx: Context): ClassDef = {
@@ -227,7 +227,7 @@ object TypedTrees {
def SharedTree(tree: Tree): SharedTree =
Trees.SharedTree(tree).withType(tree.tpe)
- def refType(sym: Symbol)(implicit ctx: Context) = NamedType.withSym(sym.owner.thisType, sym)
+ def refType(sym: Symbol)(implicit ctx: Context): NamedType = NamedType.withSym(sym.owner.thisType, sym)
// ------ Creating typed equivalents of trees that exist only in untyped form -------
@@ -239,7 +239,8 @@ object TypedTrees {
case pre => SelectFromTypeTree(TypeTree(pre), tp)
} // no checks necessary
- def ref(sym: TermSymbol)(implicit ctx: Context): tpd.NameTree = ref(sym.termRef)
+ def ref(sym: Symbol)(implicit ctx: Context): tpd.NameTree =
+ ref(NamedType(sym.owner.thisType, sym.name).withDenot(sym))
/** new C(args) */
def New(tp: Type, args: List[Tree])(implicit ctx: Context): Apply =
@@ -479,7 +480,7 @@ object TypedTrees {
check(left.isValueType); check(right.isValueType)
case RefineTypeTree(tpt, refinements) =>
check(tpt.isValueType)
- def checkRefinements(forbidden: Set[Symbol], rs: List[tpd.DefTree]): Unit = rs match {
+ def checkRefinements(forbidden: Set[Symbol], rs: List[tpd.Tree]): Unit = rs match {
case r :: rs1 =>
val rsym = r.symbol
check(rsym.isTerm || rsym.isAbstractOrAliasType)
@@ -552,7 +553,7 @@ object TypedTrees {
check(rhs.isValue)
check(rhs.tpe <:< tpt.tpe)
}
- case TypeDef(mods, name, tpt) =>
+ case TypeDef(mods, name, _, tpt) =>
check(tpt.tpe.isInstanceOf[TypeBounds])
case Template(parents, selfType, body) =>
case ClassDef(mods, name, tparams, impl) =>
diff --git a/src/dotty/tools/dotc/core/UntypedTrees.scala b/src/dotty/tools/dotc/core/UntypedTrees.scala
index 2b1d6a0d6..509c0abfb 100644
--- a/src/dotty/tools/dotc/core/UntypedTrees.scala
+++ b/src/dotty/tools/dotc/core/UntypedTrees.scala
@@ -2,7 +2,7 @@ package dotty.tools.dotc
package core
import util.Positions._, Types._, Contexts._, Constants._, Names._, Flags._
-import SymDenotations._, Symbols._, StdNames._, Annotations._, Trees._
+import SymDenotations._, Symbols._, StdNames._, Annotations._, Trees._, TypedTrees._
object UntypedTrees {
@@ -10,5 +10,24 @@ object UntypedTrees {
}
+ import untpd._
+
+ class UGen(implicit ctx: Context) {
+ def constructor(mods: Modifiers, vparamAccessorss: List[List[Tree]], ofTrait: Boolean): DefDef = ???
+
+ def Template(
+ constrMods: Modifiers,
+ vparamAccessorss: List[List[Tree]],
+ parents: List[Tree],
+ self: ValDef,
+ stats: List[Tree],
+ ofTrait: Boolean): Template = {
+ val constr = constructor(constrMods, vparamAccessorss, ofTrait)
+ Trees.Template(parents, self, vparamAccessorss.flatten ++ (constr :: stats))(NoPosition)
+ }
+ }
+
+ def ugen(implicit ctx: Context) =
+ new UGen
}