aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2013-05-22 18:02:24 +0200
committerMartin Odersky <odersky@gmail.com>2013-05-22 18:30:23 +0200
commitfd079d2f3335db7b54b0f78a4d884d9948a7beea (patch)
treecee19b71a9a077880e8d7ab1738891f55ce5bd85 /src/dotty/tools/dotc/core
parent0ebdcc7ed2d2024d93ba7d24b88187d4c502eb4b (diff)
downloaddotty-fd079d2f3335db7b54b0f78a4d884d9948a7beea.tar.gz
dotty-fd079d2f3335db7b54b0f78a4d884d9948a7beea.tar.bz2
dotty-fd079d2f3335db7b54b0f78a4d884d9948a7beea.zip
More tree refactorings.
1) Getting rid of ugen in favor of untpd. 2) Eliminating some unused methods 3) Splitting out CheckTrees from TypedTrees. 4) Moving trees and related classes into separate package dotc.ast
Diffstat (limited to 'src/dotty/tools/dotc/core')
-rw-r--r--src/dotty/tools/dotc/core/Annotations.scala2
-rw-r--r--src/dotty/tools/dotc/core/Contexts.scala2
-rw-r--r--src/dotty/tools/dotc/core/PluggableTransformers.scala105
-rw-r--r--src/dotty/tools/dotc/core/Symbols.scala8
-rw-r--r--src/dotty/tools/dotc/core/TreeInfo.scala479
-rw-r--r--src/dotty/tools/dotc/core/Trees.scala1243
-rw-r--r--src/dotty/tools/dotc/core/TypeComparers.scala3
-rw-r--r--src/dotty/tools/dotc/core/TypedTrees.scala636
-rw-r--r--src/dotty/tools/dotc/core/Types.scala4
-rw-r--r--src/dotty/tools/dotc/core/UntypedTrees.scala501
-rw-r--r--src/dotty/tools/dotc/core/pickling/ClassfileParser.scala2
-rw-r--r--src/dotty/tools/dotc/core/pickling/UnPickler.scala3
12 files changed, 14 insertions, 2974 deletions
diff --git a/src/dotty/tools/dotc/core/Annotations.scala b/src/dotty/tools/dotc/core/Annotations.scala
index 9086047cd..07ed37f06 100644
--- a/src/dotty/tools/dotc/core/Annotations.scala
+++ b/src/dotty/tools/dotc/core/Annotations.scala
@@ -1,7 +1,7 @@
package dotty.tools.dotc
package core
-import Symbols._, Types._, util.Positions._, Contexts._, Constants._, TypedTrees.tpd._
+import Symbols._, Types._, util.Positions._, Contexts._, Constants._, ast.TypedTrees.tpd._
object Annotations {
diff --git a/src/dotty/tools/dotc/core/Contexts.scala b/src/dotty/tools/dotc/core/Contexts.scala
index d29f8834d..8fcdc2cbd 100644
--- a/src/dotty/tools/dotc/core/Contexts.scala
+++ b/src/dotty/tools/dotc/core/Contexts.scala
@@ -9,7 +9,7 @@ import Phases._
import Types._
import Symbols._
import TypeComparers._, NameOps._, SymDenotations._, util.Positions._
-import TypedTrees.tpd._, util.FreshNameCreator
+import ast.TypedTrees.tpd._, util.FreshNameCreator
import config.Settings._
import config.ScalaSettings
import reporting._
diff --git a/src/dotty/tools/dotc/core/PluggableTransformers.scala b/src/dotty/tools/dotc/core/PluggableTransformers.scala
deleted file mode 100644
index caeb1c9e6..000000000
--- a/src/dotty/tools/dotc/core/PluggableTransformers.scala
+++ /dev/null
@@ -1,105 +0,0 @@
-package dotty.tools.dotc
-package core
-
-
-object PluggableTransformers {
-/*
- import Trees._, Contexts._
-
- abstract class PluggableTransformer[T] extends TreeTransformer[T, Context] {
- type PluginOp[-N <: Tree[T]] = N => Tree[T]
-
- private[this] var _ctx: Context = _
- private[this] var _oldTree: Tree[T] = _
-
- protected implicit def ctx: Context = _ctx
- protected def oldTree: Tree[T] = _oldTree
- protected def thisTransformer: PluggableTransformer[T] = this
-
- class PluginOps[-N <: Tree[T]](op: PluginOp[N], val next: Plugins) {
- def apply(tree: N, old: Tree[T], c: Context): Tree[T] = {
- val savedCtx = _ctx
- val savedOld = _oldTree
- try {
- op(tree)
- } finally {
- _oldTree = savedOld
- _ctx = savedCtx
- }
- }
- }
-
- val NoOp: PluginOp[Tree[T]] = identity
- val NoOps = new PluginOps(NoOp, null)
-
- class Plugins {
- def next: Plugins = null
-
- def processIdent: PluginOp[Ident[T]] = NoOp
- def processSelect: PluginOp[Select[T]] = NoOp
-
- val IdentOps: PluginOps[Ident[T]] = NoOps
- val SelectOps: PluginOps[Select[T]] = NoOps
- }
-
- val EmptyPlugin = new Plugins
-
- private[this] var _plugins: Plugins = EmptyPlugin
-
- override def plugins: Plugins = _plugins
-
- class Plugin extends Plugins {
- override val next = _plugins
- _plugins = this
-
- private def push[N <: Tree[T]](op: PluginOp[N], ops: => PluginOps[N]): PluginOps[N] =
- if (op == NoOp) ops else new PluginOps(op, next)
-
- override val IdentOps: PluginOps[Ident[T]] = push(processIdent, next.IdentOps)
- override val SelectOps: PluginOps[Select[T]] = push(processSelect, next.SelectOps)
- }
-
- def postIdent(tree: Ident[T], old: Tree[T], c: Context, ops: PluginOps[Ident[T]]) =
- if (ops eq NoOps) tree
- else finishIdent(ops(tree, old, c), old, c, ops.next)
-
- override def finishIdent(tree: Tree[T], old: Tree[T], c: Context, plugins: Plugins): Tree[T] = tree match {
- case tree: Ident[_] => postIdent(tree, old, c, plugins.IdentOps)
- case _ => postProcess(tree, old, c, plugins)
- }
-
- def postSelect(tree: Select[T], old: Tree[T], c: Context, ops: PluginOps[Select[T]]) =
- if (ops eq NoOps) tree
- else finishSelect(ops(tree, old, c), old, c, ops.next)
-
- override def finishSelect(tree: Tree[T], old: Tree[T], c: Context, plugins: Plugins): Tree[T] = tree match {
- case tree: Select[_] => postSelect(tree, old, c, plugins.SelectOps)
- case _ => postProcess(tree, old, c, plugins)
- }
-
- protected def postProcess(tree: Tree[T], old: Tree[T], c: Context, plugins: Plugins): Tree[T] = tree match {
- case tree: Ident[_] => finishIdent(tree, old, c, plugins)
- case tree: Select[_] => finishSelect(tree, old, c, plugins)
- }
- }
-}
-
-import PluggableTransformers._, Types._, Trees._, Contexts._, TypedTrees.tpd
-
-class ExampleTransformer extends PluggableTransformer[Type] {
-
- object ExamplePlugin extends Plugin {
- override def processIdent = {
- case tree @ Ident(x) if x.isTypeName => tree.derivedSelect(tree, x)
- case tree => tpd.Ident(???)
- }
- override def processSelect = { tree =>
- if (tree.isType) tree.derivedIdent(tree.name)
- else tpd.EmptyTree
- }
- }
-
- override def transform(tree: tpd.Tree, ctx: Context) =
- super.transform(tree, ctx)
-*/
-} \ No newline at end of file
diff --git a/src/dotty/tools/dotc/core/Symbols.scala b/src/dotty/tools/dotc/core/Symbols.scala
index b6efdcd36..8c5474740 100644
--- a/src/dotty/tools/dotc/core/Symbols.scala
+++ b/src/dotty/tools/dotc/core/Symbols.scala
@@ -12,7 +12,9 @@ import Symbols._
import Contexts._
import SymDenotations._, printing.Texts._
import printing.Printer
-import Types._, Annotations._, util.Positions._, StdNames._, Trees._, NameOps._
+import Types._, Annotations._, util.Positions._, StdNames._, NameOps._
+import ast.TypedTrees.TreeMapper
+import ast.TypedTrees.tpd.SharedTree
import Denotations.{ Denotation, SingleDenotation, MultiDenotation }
import collection.mutable
import io.AbstractFile
@@ -200,7 +202,7 @@ trait Symbols { this: Context =>
newSymbol(cls, nme.localDummyName(cls), EmptyFlags, NoType)
/** Create an import symbol pointing back to given qualifier `expr`. */
- def newImportSymbol(expr: SharedTree[Type], coord: Coord = NoCoord) =
+ def newImportSymbol(expr: SharedTree, coord: Coord = NoCoord) =
newSymbol(NoSymbol, nme.IMPORT, EmptyFlags, ImportType(expr), coord = coord)
/** Create a class constructor symbol for given class `cls`. */
@@ -251,7 +253,7 @@ trait Symbols { this: Context =>
else {
val copies: List[Symbol] = for (original <- originals) yield
newNakedSymbol[original.ThisName](original.coord)
- val treeMap = new TypedTrees.TreeMapper(typeMap, ownerMap)
+ val treeMap = new TreeMapper(typeMap, ownerMap)
.withSubstitution(originals, copies)
(originals, copies).zipped foreach {(original, copy) =>
val odenot = original.denot
diff --git a/src/dotty/tools/dotc/core/TreeInfo.scala b/src/dotty/tools/dotc/core/TreeInfo.scala
deleted file mode 100644
index 79e35170a..000000000
--- a/src/dotty/tools/dotc/core/TreeInfo.scala
+++ /dev/null
@@ -1,479 +0,0 @@
-package dotty.tools
-package dotc
-package core
-
-import Flags._, Trees._, UntypedTrees._, TypedTrees._, Types._, Contexts._
-import Names._, StdNames._, NameOps._, Decorators._, Symbols._
-import util.HashSet
-
-/** This class ...
- *
- * @author Martin Odersky
- * @version 1.0
- */
-abstract class TreeInfo {
-
- def isDeclarationOrTypeDef(tree: Tree[_ >: Untyped]): Boolean = tree match {
- case DefDef(_, _, _, _, _, EmptyTree())
- | ValDef(_, _, _, EmptyTree())
- | TypeDef(_, _, _, _) => true
- case _ => false
- }
-
- /** Is tree legal as a member definition of an interface?
- */
- def isInterfaceMember(tree: Tree[_ >: Untyped]): Boolean = tree match {
- case EmptyTree() => true
- case Import(_, _) => true
- case TypeDef(_, _, _, _) => true
- case DefDef(mods, _, _, _, _, __) => mods.flags is Deferred
- case ValDef(mods, _, _, _) => mods is Deferred
- case _ => false
- }
-
- /** Is tree a definition that has no side effects when
- * evaluated as part of a block after the first time?
- */
- def isIdempotentDef(tree: Tree[Type])(implicit ctx: Context): Boolean = tree match {
- case EmptyTree()
- | ClassDef(_, _, _, _)
- | TypeDef(_, _, _, _)
- | Import(_, _)
- | DefDef(_, _, _, _, _, _) =>
- true
- case ValDef(mods, _, _, rhs) =>
- !(mods is Mutable) && isIdempotentExpr(rhs)
- case _ =>
- false
- }
-
- /** Is tree an expression which can be inlined without affecting program semantics?
- *
- * Note that this is not called "isExprPure" since purity (lack of side-effects)
- * is not the litmus test. References to modules and lazy vals are side-effecting,
- * both because side-effecting code may be executed and because the first reference
- * takes a different code path than all to follow; but they are safe to inline
- * because the expression result from evaluating them is always the same.
- */
- def isIdempotentExpr(tree: Tree[Type])(implicit ctx: Context): Boolean = tree match {
- case EmptyTree()
- | This(_)
- | Super(_, _)
- | Literal(_) =>
- true
- case Ident(_) =>
- tree.symbol is Stable
- case Select(qual, _) =>
- tree.symbol.isStable && isIdempotentExpr(qual)
- case TypeApply(fn, _) =>
- isIdempotentExpr(fn)
-/*
- * Not sure we'll need that. Comment out until we find out
- case Apply(Select(free @ Ident(_), nme.apply), _) if free.symbol.name endsWith nme.REIFY_FREE_VALUE_SUFFIX =>
- // see a detailed explanation of this trick in `GenSymbols.reifyFreeTerm`
- free.symbol.hasStableFlag && isIdempotentExpr(free)
-*/
- case Apply(fn, Nil) =>
- // Note: After uncurry, field accesses are represented as Apply(getter, Nil),
- // so an Apply can also be pure.
- // However, before typing, applications of nullary functional values are also
- // Apply(function, Nil) trees. To prevent them from being treated as pure,
- // we check that the callee is a method.
- // The callee might also be a Block, which has a null symbol, so we guard against that (SI-7185)
- fn.symbol != null && (fn.symbol is (Method, butNot = Lazy)) && isIdempotentExpr(fn)
- case Typed(expr, _) =>
- isIdempotentExpr(expr)
- case Block(stats, expr) =>
- (stats forall isIdempotentDef) && isIdempotentExpr(expr)
- case _ =>
- false
- }
-
- class MatchingArgs[T >: Untyped](params: List[Symbol], args: List[Tree[T]])(implicit ctx: Context) {
- def foreach(f: (Symbol, Tree[T]) => Unit): Boolean = {
- def recur(params: List[Symbol], args: List[Tree[T]]): Boolean = params match {
- case Nil => args.isEmpty
- case param :: params1 =>
- if (defn.RepeatedParamClasses contains param.info.typeSymbol) {
- for (arg <- args) f(param, arg)
- true
- } else args match {
- case Nil => false
- case arg :: args1 =>
- f(param, args.head)
- recur(params1, args1)
- }
- }
- recur(params, args)
- }
- def zipped: List[(Symbol, Tree[T])] = map((_, _))
- def map[R](f: (Symbol, Tree[T]) => R): List[R] = {
- val b = List.newBuilder[R]
- foreach(b += f(_, _))
- b.result
- }
- }
-
- /** The method part of an application node, possibly enclosed in a block
- * with only valdefs as statements. the reason for also considering blocks
- * is that named arguments can transform a call into a block, e.g.
- * <init>(b = foo, a = bar)
- * is transformed to
- * { val x$1 = foo
- * val x$2 = bar
- * <init>(x$2, x$1)
- * }
- */
- def methPart[T >: Untyped](tree: Tree[T]): Tree[T] = tree match {
- case Apply(fn, _) => methPart(fn)
- case TypeApply(fn, _) => methPart(fn)
- case AppliedTypeTree(fn, _) => methPart(fn)
- case Block(stats, expr) if stats forall (_.isInstanceOf[ValDef[_]]) => methPart(expr)
- case _ => tree
- }
-
- /** Is symbol potentially a getter of a mutable variable?
- */
- def mayBeVarGetter(sym: Symbol)(implicit ctx: Context): Boolean = {
- def maybeGetterType(tpe: Type): Boolean = tpe match {
- case _: ExprType | _: ImplicitMethodType => true
- case tpe: PolyType => maybeGetterType(tpe.resultType)
- case _ => false
- }
- sym.owner.isClass && !sym.isStable && maybeGetterType(sym.info)
- }
-
- /** Is tree a reference to a mutable variable, or to a potential getter
- * that has a setter in the same class?
- */
- def isVariableOrGetter(tree: Tree[Type])(implicit ctx: Context) = {
- def sym = tree.symbol
- def isVar = sym is Mutable
- def isGetter =
- mayBeVarGetter(sym) && sym.owner.info.member(sym.name.asTermName.getterToSetter).exists
-
- tree match {
- case Ident(_) => isVar
- case Select(_, _) => isVar || isGetter
- case Apply(_, _) =>
- methPart(tree) match {
- case Select(qual, nme.apply) => qual.tpe.member(nme.update).exists
- case _ => false
- }
- case _ => false
- }
- }
-
- /** Is tree a self constructor call this(...)? I.e. a call to a constructor of the
- * same object?
- */
- def isSelfConstrCall(tree: Tree[_ >: Untyped]): Boolean = methPart(tree) match {
- case Ident(nme.CONSTRUCTOR) | Select(This(_), nme.CONSTRUCTOR) => true
- case _ => false
- }
-
- /** Is tree a super constructor call?
- */
- def isSuperConstrCall(tree: Tree[_ >: Untyped]): Boolean = methPart(tree) match {
- case Select(Super(_, _), nme.CONSTRUCTOR) => true
- case _ => false
- }
-
- def isSelfOrSuperConstrCall(tree: Tree[_ >: Untyped]): Boolean = methPart(tree) match {
- case Ident(nme.CONSTRUCTOR)
- | Select(This(_), nme.CONSTRUCTOR)
- | Select(Super(_, _), nme.CONSTRUCTOR) => true
- case _ => false
- }
-
- /** Strips layers of `.asInstanceOf[T]` / `_.$asInstanceOf[T]()` from an expression */
- def stripCast(tree: Tree[Type])(implicit ctx: Context): Tree[Type] = {
- def isCast(sel: Tree[Type]) = defn.asInstanceOfMethods contains sel.symbol
- tree match {
- case TypeApply(sel @ Select(inner, _), _) if isCast(sel) =>
- stripCast(inner)
- case Apply(TypeApply(sel @ Select(inner, _), _), Nil) if isCast(sel) =>
- stripCast(inner)
- case t =>
- t
- }
- }
-
- /** Is tree a variable pattern? */
- def isVarPattern[T >: Untyped](pat: Tree[T]): Boolean = pat match {
- case x: BackquotedIdent[_] => false
- case x: Ident[_] => x.name.isVariableName
- case _ => false
- }
-
- /** The first constructor definition in `stats` */
- def firstConstructor[T >: Untyped](stats: List[Tree[T]]): Tree[T] = stats match {
- case (meth: DefDef[_]) :: _ if meth.name.isConstructorName => meth
- case stat :: stats => firstConstructor(stats)
- case nil => EmptyTree()
- }
-
- /** The arguments to the first constructor in `stats`. */
- def firstConstructorArgs[T >: Untyped](stats: List[Tree[T]]): List[Tree[T]] = firstConstructor(stats) match {
- case DefDef(_, _, _, args :: _, _, _) => args
- case _ => Nil
- }
-
- /** The value definitions marked PRESUPER in this statement sequence */
- def preSuperFields[T >: Untyped](stats: List[Tree[T]]): List[ValDef[T]] =
- (stats filter isEarlyValDef).asInstanceOf[List[ValDef[T]]]
-
- def isEarlyDef(tree: Tree[_ >: Untyped]) = isEarlyValDef(tree) || isEarlyTypeDef(tree)
-
- def isEarlyValDef(tree: Tree[_ >: Untyped]) = tree match {
- case ValDef(mods, _, _, _) => mods is Scala2PreSuper
- case _ => false
- }
-
- def isEarlyTypeDef(tree: Tree[_ >: Untyped]) = tree match {
- case TypeDef(mods, _, _, _) => mods is Scala2PreSuper
- case _ => false
- }
-
- /** Is tpt a vararg type of the form T* ? */
- def isRepeatedParamType(tpt: Tree[_ >: Untyped])(implicit ctx: Context) = tpt match {
- case tpt: TypeTree[_] => defn.RepeatedParamClasses contains tpt.typeOpt.typeSymbol
- case AppliedTypeTree(Select(_, tpnme.REPEATED_PARAM_CLASS), _) => true
- case AppliedTypeTree(Select(_, tpnme.JAVA_REPEATED_PARAM_CLASS), _) => true
- case _ => false
- }
-
- /** Is tpt a by-name parameter type of the form => T? */
- def isByNameParamType(tpt: Tree[_ >: Untyped])(implicit ctx: Context) = tpt match {
- case tpt: TypeTree[_] => tpt.typeOpt.typeSymbol == defn.ByNameParamClass
- case AppliedTypeTree(Select(_, tpnme.BYNAME_PARAM_CLASS), _) => true
- case _ => false
- }
-
- /** Is name a left-associative operator? */
- def isLeftAssoc(operator: Name) = operator.nonEmpty && (operator.last != ':')
-
- /** Is tree a `this` node which belongs to `enclClass`? */
- def isSelf(tree: Tree[_ >: Untyped], enclClass: Symbol)(implicit ctx: Context): Boolean = tree match {
- case This(_) => tree.symbol == enclClass
- case _ => false
- }
-
- /** a Match(Typed(_, tpt), _) must be translated into a switch if isSwitchAnnotation(tpt.tpe)
- def isSwitchAnnotation(tpe: Type) = tpe hasAnnotation defn.SwitchClass
- */
-
- /** can this type be a type pattern? */
- def mayBeTypePat(tree: Tree[Untyped]): Boolean = tree match {
- case AndTypeTree(tpt1, tpt2) => mayBeTypePat(tpt1) || mayBeTypePat(tpt2)
- case OrTypeTree(tpt1, tpt2) => mayBeTypePat(tpt1) || mayBeTypePat(tpt2)
- case RefinedTypeTree(tpt, refinements) => mayBeTypePat(tpt) || refinements.exists(_.isInstanceOf[Bind[_]])
- case AppliedTypeTree(tpt, args) => mayBeTypePat(tpt) || args.exists(_.isInstanceOf[Bind[_]])
- case SelectFromTypeTree(tpt, _) => mayBeTypePat(tpt)
- case Annotated(_, tpt) => mayBeTypePat(tpt)
- case _ => false
- }
-
- /** Is this argument node of the form <expr> : _* ?
- */
- def isWildcardStarArg(tree: Tree[_ >: Untyped]): Boolean = tree match {
- case Typed(_, Ident(tpnme.WILDCARD_STAR)) => true
- case _ => false
- }
-
- /** If this tree has type parameters, those. Otherwise Nil.
- def typeParameters(tree: Tree[_]): List[TypeDef] = tree match {
- case DefDef(_, _, tparams, _, _, _) => tparams
- case ClassDef(_, _, tparams, _) => tparams
- case TypeDef(_, _, tparams, _) => tparams
- case _ => Nil
- }*/
-
- /** Does this argument list end with an argument of the form <expr> : _* ? */
- def isWildcardStarArgList(trees: List[Tree[_ >: Untyped]]) =
- trees.nonEmpty && isWildcardStarArg(trees.last)
-
- /** Is the argument a wildcard argument of the form `_` or `x @ _`?
- */
- def isWildcardArg(tree: Tree[_ >: Untyped]): Boolean = unbind(tree) match {
- case Ident(nme.WILDCARD) => true
- case _ => false
- }
-
- /** Is the argument a wildcard star type of the form `_*`?
- */
- def isWildcardStarType(tree: Tree[_ >: Untyped]): Boolean = tree match {
- case Ident(tpnme.WILDCARD_STAR) => true
- case _ => false
- }
-
- /** Is this pattern node a catch-all (wildcard or variable) pattern? */
- def isDefaultCase(cdef: CaseDef[_ >: Untyped]) = cdef match {
- case CaseDef(pat, EmptyTree(), _) => isWildcardArg(pat)
- case _ => false
- }
-
- /** Is this pattern node a synthetic catch-all case, added during PartialFuction synthesis before we know
- * whether the user provided cases are exhaustive. */
- def isSyntheticDefaultCase(cdef: CaseDef[_ >: Untyped]) = cdef match {
- case CaseDef(Bind(nme.DEFAULT_CASE, _), EmptyTree(), _) => true
- case _ => false
- }
-
- /** Does this CaseDef catch Throwable? */
- def catchesThrowable(cdef: CaseDef[_ >: Untyped])(implicit ctx: Context) =
- catchesAllOf(cdef, defn.ThrowableClass.typeConstructor)
-
- /** Does this CaseDef catch everything of a certain Type? */
- def catchesAllOf(cdef: CaseDef[_ >: Untyped], threshold: Type)(implicit ctx: Context) =
- isDefaultCase(cdef) ||
- cdef.guard.isEmpty && {
- unbind(cdef.pat) match {
- case Typed(Ident(nme.WILDCARD), tpt) => threshold <:< tpt.typeOpt
- case _ => false
- }
- }
-
- /** Is this pattern node a catch-all or type-test pattern? */
- def isCatchCase(cdef: CaseDef[Type])(implicit ctx: Context) = cdef match {
- case CaseDef(Typed(Ident(nme.WILDCARD), tpt), EmptyTree(), _) =>
- isSimpleThrowable(tpt.tpe)
- case CaseDef(Bind(_, Typed(Ident(nme.WILDCARD), tpt)), EmptyTree(), _) =>
- isSimpleThrowable(tpt.tpe)
- case _ =>
- isDefaultCase(cdef)
- }
-
- private def isSimpleThrowable(tp: Type)(implicit ctx: Context): Boolean = tp match {
- case tp @ TypeRef(pre, _) =>
- (pre == NoPrefix || pre.widen.typeSymbol.isStatic) &&
- (tp.symbol derivesFrom defn.ThrowableClass) && !(tp.symbol is Trait)
- case _ =>
- false
- }
-
- /** Is this case guarded? */
- def isGuardedCase(cdef: CaseDef[_ >: Untyped]) = cdef.guard != EmptyTree()
-
- /** Is this pattern node a sequence-valued pattern? */
- def isSequenceValued(tree: Tree[_ >: Untyped]): Boolean = unbind(tree) match {
- case Alternative(ts) => ts exists isSequenceValued
- case SeqLiteral(_, _) => true
- case _ => false
- }
-
- /** The underlying pattern ignoring any bindings */
- def unbind[T >: Untyped](x: Tree[T]): Tree[T] = x match {
- case Bind(_, y) => unbind(y)
- case y => y
- }
-
-
- /** Does list of trees start with a definition of
- * a class of module with given name (ignoring imports)
- def firstDefinesClassOrObject(trees: List[Tree], name: Name): Boolean = trees match {
- case Import(_, _) :: xs => firstDefinesClassOrObject(xs, name)
- case Annotated(_, tree1) :: Nil => firstDefinesClassOrObject(List(tree1), name)
- case ModuleDef(_, `name`, _) :: Nil => true
- case ClassDef(_, `name`, _, _) :: Nil => true
- case _ => false
- }
-
-
- /** Is this file the body of a compilation unit which should not
- * have Predef imported?
- */
- def noPredefImportForUnit(body: Tree) = {
- // Top-level definition whose leading imports include Predef.
- def isLeadingPredefImport(defn: Tree): Boolean = defn match {
- case PackageDef(_, defs1) => defs1 exists isLeadingPredefImport
- case Import(expr, _) => isReferenceToPredef(expr)
- case _ => false
- }
- // Compilation unit is class or object 'name' in package 'scala'
- def isUnitInScala(tree: Tree, name: Name) = tree match {
- case PackageDef(Ident(nme.scala_), defs) => firstDefinesClassOrObject(defs, name)
- case _ => false
- }
-
- isUnitInScala(body, nme.Predef) || isLeadingPredefImport(body)
- }
- */
-
- /*
- def isAbsTypeDef(tree: Tree) = tree match {
- case TypeDef(_, _, _, TypeBoundsTree(_, _)) => true
- case TypeDef(_, _, _, rhs) => rhs.tpe.isInstanceOf[TypeBounds]
- case _ => false
- }
-
- def isAliasTypeDef(tree: Tree) = tree match {
- case TypeDef(_, _, _, _) => !isAbsTypeDef(tree)
- case _ => false
- }
-
- /** Some handy extractors for spotting trees through the
- * the haze of irrelevant braces: i.e. Block(Nil, SomeTree)
- * should not keep us from seeing SomeTree.
- */
- abstract class SeeThroughBlocks[T] {
- protected def unapplyImpl(x: Tree): T
- def unapply(x: Tree): T = x match {
- case Block(Nil, expr) => unapply(expr)
- case _ => unapplyImpl(x)
- }
- }
- object IsTrue extends SeeThroughBlocks[Boolean] {
- protected def unapplyImpl(x: Tree): Boolean = x match {
- case Literal(Constant(true)) => true
- case _ => false
- }
- }
- object IsFalse extends SeeThroughBlocks[Boolean] {
- protected def unapplyImpl(x: Tree): Boolean = x match {
- case Literal(Constant(false)) => true
- case _ => false
- }
- }
- object IsIf extends SeeThroughBlocks[Option[(Tree, Tree, Tree)]] {
- protected def unapplyImpl(x: Tree) = x match {
- case If(cond, thenp, elsep) => Some((cond, thenp, elsep))
- case _ => None
- }
- }
-
- def isApplyDynamicName(name: Name) = (name == nme.updateDynamic) || (name == nme.selectDynamic) || (name == nme.applyDynamic) || (name == nme.applyDynamicNamed)
-
- class DynamicApplicationExtractor(nameTest: Name => Boolean) {
- def unapply(tree: Tree) = tree match {
- case Apply(TypeApply(Select(qual, oper), _), List(Literal(Constant(name)))) if nameTest(oper) => Some((qual, name))
- case Apply(Select(qual, oper), List(Literal(Constant(name)))) if nameTest(oper) => Some((qual, name))
- case Apply(Ident(oper), List(Literal(Constant(name)))) if nameTest(oper) => Some((EmptyTree(), name))
- case _ => None
- }
- }
- object DynamicUpdate extends DynamicApplicationExtractor(_ == nme.updateDynamic)
- object DynamicApplication extends DynamicApplicationExtractor(isApplyDynamicName)
- object DynamicApplicationNamed extends DynamicApplicationExtractor(_ == nme.applyDynamicNamed)
-
- object MacroImplReference {
- private def refPart(tree: Tree): Tree = tree match {
- case TypeApply(fun, _) => refPart(fun)
- case ref: RefTree => ref
- case _ => EmptyTree()
- }
-
- def unapply(tree: Tree) = refPart(tree) match {
- case ref: RefTree => Some((ref.qualifier.symbol, ref.symbol, dissectApplied(tree).targs))
- case _ => None
- }
- }
-
- def isNullaryInvocation(tree: Tree): Boolean =
- tree.symbol != null && tree.symbol.isMethod && (tree match {
- case TypeApply(fun, _) => isNullaryInvocation(fun)
- case tree: RefTree => true
- case _ => false
- })*/
-}
-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
deleted file mode 100644
index 4cb65cf3b..000000000
--- a/src/dotty/tools/dotc/core/Trees.scala
+++ /dev/null
@@ -1,1243 +0,0 @@
-package dotty.tools.dotc
-package core
-
-import Types._, Names._, Flags._, util.Positions._, Contexts._, Constants._, SymDenotations._, Symbols._
-import Denotations._, StdNames._
-import annotation.tailrec
-import language.higherKinds
-import collection.mutable
-import collection.mutable.ArrayBuffer
-import parsing.Tokens.Token
-import printing.Printer
-import util.Stats
-
-object Trees {
-
- // Note: it would be more logical to make Untyped = Nothing.
- // However, this interacts in a bad way with Scala's current type inference.
- // In fact, we cannot write soemthing like Select(pre, name), where pre is
- // of type Tree[Nothing]; type inference will treat the Nothing as an uninstantited
- // value and will not infer Nothing as the type parameter for Select.
- // We should come back to this issue once type inference is changed.
- type Untyped = Null
- type TypedTree = Tree[Type]
- type UntypedTree = Tree[Untyped]
-
- /** The total number of created tree nodes, maintained if Stats.enabled */
- var ntrees = 0
-
- /** A base class for things that have positions (currently: modifiers and trees)
- */
- abstract class Positioned extends DotClass with Product {
-
- private var curPos: Position = initialPos
-
- /** The item's position.
- */
- def pos: Position = curPos
-
- /** The envelope containing the item in its entirety. Envelope is different from
- * `pos` for definitions (instances of ModDefTree).
- */
- def envelope: Position = curPos.toSynthetic
-
- /** A positioned item like this one with the position set to `pos`.
- * if the positioned item is source-derived, a clone is returned.
- * If the positioned item is synthetic, the position is updated
- * destructively and the item itself is returned.
- */
- def withPos(pos: Position): this.type = {
- val newpd = (if (pos != curPos && curPos.isSynthetic) this else clone).asInstanceOf[Positioned]
- newpd.curPos = pos
- newpd.asInstanceOf[this.type]
- }
-
- /** This item with a position that's the union of the given `pos` and the
- * current position.
- */
- def addPos(pos: Position): this.type = withPos(pos union this.pos)
-
- /** The initial, synthetic position. This is usually the union of all positioned children's
- * envelopes.
- */
- protected def initialPos: Position = {
- var n = productArity
- var pos = NoPosition
- while (n > 0) {
- n -= 1
- productElement(n) match {
- case p: Positioned => pos = pos union p.envelope
- case xs: List[_] => pos = unionPos(pos, xs)
- case _ =>
- }
- }
- pos.toSynthetic
- }
-
- private def unionPos(pos: Position, xs: List[_]): Position = xs match {
- case (t: Tree[_]) :: xs1 => unionPos(pos union t.envelope, xs1)
- case _ => pos
- }
- }
-
- /** 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).
- * If there is no opening keyword, point should equal end.
- */
- case class Modifiers[T >: Untyped] (
- flags: FlagSet = EmptyFlags,
- privateWithin: TypeName = tpnme.EMPTY,
- annotations: List[Tree[T]] = Nil) extends Positioned with Cloneable {
-
- def | (fs: FlagSet): Modifiers[T] = copy(flags = flags | fs)
- def & (fs: FlagSet): Modifiers[T] = copy(flags = flags & fs)
- def &~(fs: FlagSet): Modifiers[T] = copy(flags = flags &~ fs)
-
- def is(fs: FlagSet): Boolean = flags is fs
- def is(fc: FlagConjunction): Boolean = flags is fc
-
- def withAnnotations(annots: List[Tree[T]]) =
- if (annots.isEmpty) this
- else copy(annotations = annotations ++ annots)
-
- def withPrivateWithin(pw: TypeName) =
- if (pw.isEmpty) this
- else copy(privateWithin = pw)
-
- def hasFlags = flags != EmptyFlags
- def hasAnnotations = annotations.nonEmpty
- def hasPrivateWithin = privateWithin != tpnme.EMPTY
-
- def tokenPos: Seq[(Token, Position)] = ???
- }
-
- /** Trees take a parameter indicating what the type of their `tpe` field
- * is. Two choices: `Type` or `Untyped`.
- * Untyped trees have type `Tree[Untyped]`.
- *
- * Tree typing uses a copy-on-write implementation:
- *
- * - You can never observe a `tpe` which is `null` (throws an exception)
- * - So when creating a typed tree with `withType` we can re-use
- * the existing tree transparently, assigning its `tpe` field,
- * provided it was `null` before.
- * - It is impossible to embed untyped trees in typed ones.
- * - Typed trees can be embedded untyped ones provided they are rooted
- * in a TypedSplice node.
- * - Type checking an untyped tree should remove all embedded `TypedSplice`
- * nodes.
- */
- abstract class Tree[T >: Untyped] extends Positioned with Product with printing.Showable with Cloneable {
-
- if (Stats.enabled) ntrees += 1
-
- /** The type constructor at the root of the tree */
- type ThisTree[T >: Untyped] <: Tree[T]
-
- private var _tpe: T = _
-
- /** The type of the tree. In case of an untyped tree,
- * an UnAssignedTypeException is thrown. (Overridden by empty trees)
- */
- def tpe: T = {
- if (_tpe == null) throw new UnAssignedTypeException(this)
- _tpe
- }
-
- /** Copy `tpe` attribute from tree `from` into this tree, independently
- * whether it is null or not.
- */
- final def copyAttr(from: Tree[T]): ThisTree[T] = {
- _tpe = from._tpe
- this.withPos(from.pos).asInstanceOf[ThisTree[T]]
- }
-
- /** Return a typed tree that's isomorphic to this tree, but has given
- * type. (Overridden by empty trees)
- */
- def withType(tpe: Type): ThisTree[Type] = {
- val tree =
- (if (_tpe == null ||
- (_tpe.asInstanceOf[AnyRef] eq tpe.asInstanceOf[AnyRef])) this
- else clone).asInstanceOf[Tree[Type]]
- tree._tpe = tpe
- tree.asInstanceOf[ThisTree[Type]]
- }
-
- /** Does the tree have its type field set? Note: this operation is not
- * referentially transparent, because it can observe the withType
- * modifications. Should be used only in special circumstances (we
- * need it for printing trees with optional type info).
- */
- final def hasType: Boolean = _tpe != null
-
- final def typeOpt: Type = _tpe match {
- case tp: Type => tp
- case _ => NoType
- }
-
- /** The denotation referred tno by this tree.
- * Defined for `DenotingTree`s and `ProxyTree`s, NoDenotation for other
- * kinds of trees
- */
- def denot(implicit ctx: Context): Denotation = NoDenotation
-
- /** Shorthand for `denot.symbol`. */
- final def symbol(implicit ctx: Context): Symbol = denot.symbol
-
- /** Does this tree represent a type? */
- def isType: Boolean = false
-
- /** Does this tree represent a term? */
- def isTerm: Boolean = false
-
- /** Is this a legal part of a pattern which is not at the same time a term? */
- def isPattern: Boolean = false
-
- /** Does this tree define a new symbol that is not defined elsewhere? */
- def isDef: Boolean = false
-
- /** 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(printer: Printer) = printer.toText(this)
-
- override def hashCode(): Int = System.identityHashCode(this)
- override def equals(that: Any) = this eq that.asInstanceOf[AnyRef]
- }
-
- class UnAssignedTypeException[T >: Untyped](tree: Tree[T]) extends RuntimeException {
- override def getMessage: String = s"type of $tree is not assigned"
- }
-
- // ------ Categories of trees -----------------------------------
-
- /** Instances of this class are trees for which isType is definitely true.
- * Note that some trees have isType = true without being TypTrees (e.g. Ident, AnnotatedTree)
- */
- trait TypTree[T >: Untyped] extends Tree[T] {
- type ThisTree[T >: Untyped] <: TypTree[T]
- override def isType = true
- }
-
- /** Instances of this class are trees for which isTerm is definitely true.
- * Note that some trees have isTerm = true without being TermTrees (e.g. Ident, AnnotatedTree)
- */
- trait TermTree[T >: Untyped] extends Tree[T] {
- type ThisTree[T >: Untyped] <: TermTree[T]
- override def isTerm = true
- }
-
- /** Instances of this class are trees which are not terms but are legal
- * parts of patterns.
- */
- trait PatternTree[T >: Untyped] extends Tree[T] {
- type ThisTree[T >: Untyped] <: PatternTree[T]
- override def isPattern = true
- }
-
- /** Tree's denotation can be derived from its type */
- abstract class DenotingTree[T >: Untyped] extends Tree[T] {
- type ThisTree[T >: Untyped] <: DenotingTree[T]
- override def denot(implicit ctx: Context) = tpe match {
- case tpe: NamedType => tpe.denot
- case _ => NoDenotation
- }
- }
-
- /** Tree's denot/isType/isTerm properties come from a subtree
- * identified by `forwardTo`.
- */
- abstract class ProxyTree[T >: Untyped] extends Tree[T] {
- type ThisTree[T >: Untyped] <: ProxyTree[T]
- def forwardTo: Tree[T]
- override def denot(implicit ctx: Context): Denotation = forwardTo.denot
- override def isTerm = forwardTo.isTerm
- override def isType = forwardTo.isType
- }
-
- /** Tree has a name */
- abstract class NameTree[T >: Untyped] extends DenotingTree[T] {
- type ThisTree[T >: Untyped] <: NameTree[T]
- def name: Name
- }
-
- /** Tree refers by name to a denotation */
- abstract class RefTree[T >: Untyped] extends NameTree[T] {
- type ThisTree[T >: Untyped] <: RefTree[T]
- def qualifier: Tree[T]
- override def isType = name.isTypeName
- override def isTerm = name.isTermName
- }
-
- /** Tree defines a new symbol */
- trait DefTree[T >: Untyped] extends DenotingTree[T] {
- type ThisTree[T >: Untyped] <: DefTree[T]
- override def isDef = true
- }
-
- /** Tree defines a new symbol and carries modifiers.
- * The position of a ModDefTree contains only the defined identifier or pattern.
- * The envelope of a ModDefTree contains the whole definition and his its point
- * on the opening keyword (or the next token after that if keyword is missing).
- */
- trait ModDefTree[T >: Untyped] extends DefTree[T] {
- type ThisTree[T >: Untyped] <: ModDefTree[T]
- def mods: Modifiers[T]
- override def envelope: Position = mods.pos union pos union initialPos
- }
-
- // ----------- Tree case classes ------------------------------------
-
- /** name */
- case class Ident[T >: Untyped](name: Name)
- extends RefTree[T] {
- type ThisTree[T >: Untyped] = Ident[T]
- def qualifier: Tree[T] = EmptyTree[T]
- }
-
- class BackquotedIdent[T >: Untyped](name: Name)
- extends Ident[T](name)
-
- /** qualifier.name */
- case class Select[T >: Untyped](qualifier: Tree[T], name: Name)
- extends RefTree[T] {
- type ThisTree[T >: Untyped] = Select[T]
- }
-
- /** qual.this */
- case class This[T >: Untyped](qual: TypeName)
- extends DenotingTree[T] with TermTree[T] {
- type ThisTree[T >: Untyped] = This[T]
- }
-
- /** C.super[mix], where qual = C.this */
- case class Super[T >: Untyped](qual: Tree[T], mix: TypeName)
- extends ProxyTree[T] with TermTree[T] {
- type ThisTree[T >: Untyped] = Super[T]
- def forwardTo = qual
- }
-
- abstract class GenericApply[T >: Untyped] extends ProxyTree[T] with TermTree[T] {
- type ThisTree[T >: Untyped] <: GenericApply[T]
- val fun: Tree[T]
- val args: List[Tree[T]]
- def forwardTo = fun
- }
-
- /** fun(args) */
- case class Apply[T >: Untyped](fun: Tree[T], args: List[Tree[T]])
- extends GenericApply[T] {
- type ThisTree[T >: Untyped] = Apply[T]
- }
-
- /** fun[args] */
- case class TypeApply[T >: Untyped](fun: Tree[T], args: List[Tree[T]])
- extends GenericApply[T] {
- type ThisTree[T >: Untyped] = TypeApply[T]
- }
-
- /** const */
- case class Literal[T >: Untyped](const: Constant)
- extends TermTree[T] {
- type ThisTree[T >: Untyped] = Literal[T]
- }
-
- /** new tpt, but no constructor call */
- case class New[T >: Untyped](tpt: Tree[T])
- extends TermTree[T] {
- type ThisTree[T >: Untyped] = New[T]
- }
-
- /** new tpt(args1)...(args_n)
- */
- def New[T >: Untyped](tpt: Tree[T], argss: List[List[Tree[T]]]): Tree[T] =
- ((Select(New(tpt), nme.CONSTRUCTOR): Tree[T]) /: argss)(Apply(_, _))
-
- /** (left, right) */
- case class Pair[T >: Untyped](left: Tree[T], right: Tree[T])
- extends TermTree[T] {
- type ThisTree[T >: Untyped] = Pair[T]
- override def isTerm = left.isTerm && right.isTerm
- override def isType = left.isType && right.isType
- override def isPattern = !isTerm && (left.isPattern || left.isTerm) && (right.isPattern || right.isTerm)
- }
-
- /** expr : tpt */
- case class Typed[T >: Untyped](expr: Tree[T], tpt: Tree[T])
- extends ProxyTree[T] with TermTree[T] {
- type ThisTree[T >: Untyped] = Typed[T]
- def forwardTo = expr
- }
-
- /** name = arg, in a parameter list */
- case class NamedArg[T >: Untyped](name: Name, arg: Tree[T])
- extends Tree[T] {
- type ThisTree[T >: Untyped] = NamedArg[T]
- }
-
- /** name = arg, outside a parameter list */
- case class Assign[T >: Untyped](lhs: Tree[T], rhs: Tree[T])
- extends TermTree[T] {
- type ThisTree[T >: Untyped] = Assign[T]
- }
-
- /** { stats; expr } */
- case class Block[T >: Untyped](stats: List[Tree[T]], expr: Tree[T])
- extends TermTree[T] {
- type ThisTree[T >: Untyped] = Block[T]
- }
-
- /** if cond then thenp else elsep */
- case class If[T >: Untyped](cond: Tree[T], thenp: Tree[T], elsep: Tree[T])
- extends TermTree[T] {
- type ThisTree[T >: Untyped] = If[T]
- }
-
- /** selector match { cases } */
- case class Match[T >: Untyped](selector: Tree[T], cases: List[CaseDef[T]])
- extends TermTree[T] {
- type ThisTree[T >: Untyped] = Match[T]
- }
-
- /** case pat if guard => body */
- case class CaseDef[T >: Untyped](pat: Tree[T], guard: Tree[T], body: Tree[T])
- extends Tree[T] {
- type ThisTree[T >: Untyped] = CaseDef[T]
- }
-
- /** return expr
- * where `from` refers to the method from which the return takes place
- * After program transformations this is not necessarily the enclosing method, because
- * closures can intervene.
- */
- case class Return[T >: Untyped](expr: Tree[T], from: Tree[T] = EmptyTree[T]())
- extends TermTree[T] {
- type ThisTree[T >: Untyped] = Return[T]
- }
-
- /** try block catch handler finally finalizer */
- case class Try[T >: Untyped](expr: Tree[T], handler: Tree[T], finalizer: Tree[T])
- extends TermTree[T] {
- type ThisTree[T >: Untyped] = Try[T]
- }
-
- /** throw expr */
- case class Throw[T >: Untyped](expr: Tree[T])
- extends TermTree[T] {
- type ThisTree[T >: Untyped] = Throw[T]
- }
-
- /** Array[elemtpt](elems) */
- case class SeqLiteral[T >: Untyped](elemtpt: Tree[T], elems: List[Tree[T]])
- extends Tree[T] {
- type ThisTree[T >: Untyped] = SeqLiteral[T]
- }
-
- /** A type tree that represents an existing or inferred type */
- case class TypeTree[T >: Untyped](original: Tree[T] = EmptyTree[T])
- extends DenotingTree[T] with TypTree[T] {
- type ThisTree[T >: Untyped] = TypeTree[T]
- override def initialPos = NoPosition
- override def isEmpty = !hasType && original.isEmpty
- }
-
- /** ref.type */
- case class SingletonTypeTree[T >: Untyped](ref: Tree[T])
- extends DenotingTree[T] with TypTree[T] {
- type ThisTree[T >: Untyped] = SingletonTypeTree[T]
- }
-
- /** qualifier # name */
- case class SelectFromTypeTree[T >: Untyped](qualifier: Tree[T], name: Name)
- extends RefTree[T] {
- type ThisTree[T >: Untyped] = SelectFromTypeTree[T]
- }
-
- /** left & right */
- case class AndTypeTree[T >: Untyped](left: Tree[T], right: Tree[T])
- extends TypTree[T] {
- type ThisTree[T >: Untyped] = AndTypeTree[T]
- }
-
- /** left | right */
- case class OrTypeTree[T >: Untyped](left: Tree[T], right: Tree[T])
- extends TypTree[T] {
- type ThisTree[T >: Untyped] = OrTypeTree[T]
- }
-
- /** tpt { refinements } */
- case class RefinedTypeTree[T >: Untyped](tpt: Tree[T], refinements: List[Tree[T]])
- extends ProxyTree[T] with TypTree[T] {
- type ThisTree[T >: Untyped] = RefinedTypeTree[T]
- def forwardTo = tpt
- }
-
- /** tpt[args] */
- case class AppliedTypeTree[T >: Untyped](tpt: Tree[T], args: List[Tree[T]])
- extends ProxyTree[T] with TypTree[T] {
- type ThisTree[T >: Untyped] = AppliedTypeTree[T]
- def forwardTo = tpt
- }
-
- def AppliedTypeTree[T >: Untyped](tpt: Tree[T], arg: Tree[T]): AppliedTypeTree[T] =
- AppliedTypeTree(tpt, arg :: Nil)
-
- /** >: lo <: hi */
- case class TypeBoundsTree[T >: Untyped](lo: Tree[T], hi: Tree[T])
- extends Tree[T] {
- type ThisTree[T >: Untyped] = TypeBoundsTree[T]
- }
-
- /** name @ body */
- case class Bind[T >: Untyped](name: Name, body: Tree[T])
- extends NameTree[T] with DefTree[T] with PatternTree[T] {
- type ThisTree[T >: Untyped] = Bind[T]
- override def envelope: Position = pos union initialPos
- }
-
- /** tree_1 | ... | tree_n */
- case class Alternative[T >: Untyped](trees: List[Tree[T]])
- extends PatternTree[T] {
- type ThisTree[T >: Untyped] = Alternative[T]
- }
-
- /** fun(args) in a pattern, if fun is an extractor */
- case class UnApply[T >: Untyped](fun: Tree[T], args: List[Tree[T]])
- extends PatternTree[T] {
- type ThisTree[T >: Untyped] = UnApply[T]
- }
-
- /** mods val name: tpt = rhs */
- case class ValDef[T >: Untyped](mods: Modifiers[T], name: TermName, tpt: Tree[T], rhs: Tree[T])
- extends NameTree[T] with ModDefTree[T] {
- type ThisTree[T >: Untyped] = ValDef[T]
- }
-
- /** 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])
- extends NameTree[T] with ModDefTree[T] {
- type ThisTree[T >: Untyped] = DefDef[T]
- }
-
- /** 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, tparams: List[TypeDef[T]], rhs: Tree[T])
- extends NameTree[T] with ModDefTree[T] {
- type ThisTree[T >: Untyped] = TypeDef[T]
- }
-
- /** extends parents { self => body } */
- case class Template[T >: Untyped](constr: DefDef[T], parents: List[Tree[T]], self: ValDef[T], body: List[Tree[T]])
- extends DefTree[T] {
- type ThisTree[T >: Untyped] = Template[T]
- }
-
- /** mods class name[tparams] impl */
- case class ClassDef[T >: Untyped](mods: Modifiers[T], name: TypeName, tparams: List[TypeDef[T]], impl: Template[T])
- extends NameTree[T] with ModDefTree[T] {
- type ThisTree[T >: Untyped] = ClassDef[T]
- }
-
- /** import expr.selectors
- * where a selector is either an untyped `Ident`, `name` or
- * an untyped `Pair` `name => rename`
- */
- case class Import[T >: Untyped](expr: Tree[T], selectors: List[UntypedTree])
- extends DenotingTree[T] {
- type ThisTree[T >: Untyped] = Import[T]
- }
-
- /** package pid { stats } */
- case class PackageDef[T >: Untyped](pid: RefTree[T], stats: List[Tree[T]])
- extends ProxyTree[T] {
- type ThisTree[T >: Untyped] = PackageDef[T]
- def forwardTo = pid
- }
-
- /** arg @annot */
- case class Annotated[T >: Untyped](annot: Tree[T], arg: Tree[T])
- extends ProxyTree[T] {
- type ThisTree[T >: Untyped] = Annotated[T]
- def forwardTo = arg
- }
-
- trait AlwaysEmpty[T >: Untyped] extends Tree[T] {
- override val pos = NoPosition
- override def tpe = unsupported("tpe")
- override def withType(tpe: Type) = unsupported("withType")
- override def isEmpty: Boolean = true
- }
-
- /** A missing tree */
- abstract case class EmptyTree[T >: Untyped]()
- extends Tree[T] with AlwaysEmpty[T] {
- type ThisTree[T >: Untyped] = EmptyTree[T]
- }
-
- private object theEmptyTree extends EmptyTree[Untyped]
-
- object EmptyTree {
- def apply[T >: Untyped](): EmptyTree[T] = theEmptyTree.asInstanceOf[EmptyTree[T]]
- }
-
- class EmptyValDef[T >: Untyped] extends ValDef[T](
- Modifiers[T](Private), nme.WILDCARD, EmptyTree[T], EmptyTree[T]) with AlwaysEmpty[T]
-
- private object theEmptyValDef extends EmptyValDef[Untyped]
-
- object EmptyValDef {
- def apply[T >: Untyped](): EmptyValDef[T] = theEmptyValDef.asInstanceOf[EmptyValDef[T]]
- }
-
- /** A tree that can be shared without its position
- * polluting containing trees. Accumulators and tranformers
- * memoize results of shared subtrees
- */
- case class SharedTree[T >: Untyped](shared: Tree[T]) extends ProxyTree[T] {
- type ThisTree[T >: Untyped] = SharedTree[T]
- def forwardTo: Tree[T] = shared
- }
-
- // ----- Auxiliary creation methods ------------------
-
- def Block[T >: Untyped](stat: Tree[T], expr: Tree[T]): Block[T] =
- Block(stat :: Nil, expr)
-
- def Apply[T >: Untyped](fn: Tree[T], arg: Tree[T]): Apply[T] =
- Apply(fn, arg :: Nil)
-
- // ----- Generic Tree Instances, inherited from `tpt` and `untpd`.
-
- abstract class Instance[T >: Untyped] {
-
- type Modifiers = Trees.Modifiers[T]
- type Tree = Trees.Tree[T]
- type TypTree = Trees.TypTree[T]
- type TermTree = Trees.TermTree[T]
- type PatternTree = Trees.PatternTree[T]
- type DenotingTree = Trees.DenotingTree[T]
- type ProxyTree = Trees.ProxyTree[T]
- type NameTree = Trees.NameTree[T]
- type RefTree = Trees.RefTree[T]
- type DefTree = Trees.DefTree[T]
- type ModDefTree = Trees.ModDefTree[T]
-
- type TreeCopier = Trees.TreeCopier[T]
- type TreeAccumulator[U] = Trees.TreeAccumulator[U, T]
- type TreeTransformer = Trees.TreeTransformer[T]
-
- type Ident = Trees.Ident[T]
- type Select = Trees.Select[T]
- type This = Trees.This[T]
- type Super = Trees.Super[T]
- type Apply = Trees.Apply[T]
- type TypeApply = Trees.TypeApply[T]
- type Literal = Trees.Literal[T]
- type New = Trees.New[T]
- type Pair = Trees.Pair[T]
- type Typed = Trees.Typed[T]
- type NamedArg = Trees.NamedArg[T]
- type Assign = Trees.Assign[T]
- type Block = Trees.Block[T]
- type If = Trees.If[T]
- type Match = Trees.Match[T]
- type CaseDef = Trees.CaseDef[T]
- type Return = Trees.Return[T]
- type Try = Trees.Try[T]
- type Throw = Trees.Throw[T]
- type SeqLiteral = Trees.SeqLiteral[T]
- type TypeTree = Trees.TypeTree[T]
- type SingletonTypeTree = Trees.SingletonTypeTree[T]
- type SelectFromTypeTree = Trees.SelectFromTypeTree[T]
- type AndTypeTree = Trees.AndTypeTree[T]
- type OrTypeTree = Trees.OrTypeTree[T]
- type RefinedTypeTree = Trees.RefinedTypeTree[T]
- type AppliedTypeTree = Trees.AppliedTypeTree[T]
- type TypeBoundsTree = Trees.TypeBoundsTree[T]
- type Bind = Trees.Bind[T]
- type Alternative = Trees.Alternative[T]
- type UnApply = Trees.UnApply[T]
- type ValDef = Trees.ValDef[T]
- type DefDef = Trees.DefDef[T]
- type TypeDef = Trees.TypeDef[T]
- type Template = Trees.Template[T]
- type ClassDef = Trees.ClassDef[T]
- type Import = Trees.Import[T]
- type PackageDef = Trees.PackageDef[T]
- type Annotated = Trees.Annotated[T]
- type EmptyTree = Trees.EmptyTree[T]
- type SharedTree = Trees.SharedTree[T]
-
- protected implicit def pos(implicit ctx: Context): Position = ctx.position
-
- def defPos(sym: Symbol)(implicit ctx: Context) = ctx.position union sym.coord.toPosition
-
- def Parameter(pname: TermName, tpe: Tree, mods: Modifiers = Modifiers()): ValDef =
- ValDef(mods | Param, pname, tpe, EmptyTree())
-
- /** Temporary class that results from translation of ModuleDefs
- * (and possibly other statements).
- * The contained trees will be integrated in enclosing Blocks or Templates
- */
- case class TempTrees(trees: List[Tree]) extends Tree {
- override def tpe: T = unsupported("tpe")
- }
-
- /** Integrates nested TempTrees in given list of trees */
- def flatten(trees: List[Tree]): List[Tree] =
- if (trees exists isTempTrees)
- trees flatMap {
- case TempTrees(ts) => ts
- case t => t :: Nil
- }
- else trees
-
- def combine(trees: List[Tree]): Tree = flatten(trees) match {
- case tree :: Nil => tree
- case ts => TempTrees(ts)
- }
-
- private val isTempTrees: Tree => Boolean = (_.isInstanceOf[TempTrees])
- }
-
- // ----- Helper functions and classes ---------------------------------------
-
- implicit class TreeCopier[T >: Untyped](val tree: Tree[T]) extends AnyVal {
- def derivedIdent(name: Name): Ident[T] = tree match {
- case tree: BackquotedIdent[_] =>
- if (name == tree.name) tree
- else new BackquotedIdent[T](name).copyAttr(tree)
- case tree: Ident[_] if (name == tree.name) => tree
- case _ => Ident[T](name).copyAttr(tree)
- }
- def derivedSelect(qualifier: Tree[T], name: Name): Select[T] = tree match {
- case tree: Select[_] if (qualifier eq tree.qualifier) && (name == tree.name) => tree
- case _ => Select(qualifier, name).copyAttr(tree)
- }
- def derivedThis(qual: TypeName): This[T] = tree match {
- case tree: This[_] if (qual == tree.qual) => tree
- case _ => This[T](qual).copyAttr(tree)
- }
- def derivedSuper(qual: Tree[T], mix: TypeName): Super[T] = tree match {
- case tree: Super[_] if (qual eq tree.qual) && (mix == tree.mix) => tree
- case _ => Super(qual, mix).copyAttr(tree)
- }
- def derivedApply(fun: Tree[T], args: List[Tree[T]]): Apply[T] = tree match {
- case tree: Apply[_] if (fun eq tree.fun) && (args eq tree.args) => tree
- case _ => Apply(fun, args).copyAttr(tree)
- }
- def derivedTypeApply(fun: Tree[T], args: List[Tree[T]]): TypeApply[T] = tree match {
- case tree: TypeApply[_] if (fun eq tree.fun) && (args eq tree.args) => tree
- case _ => TypeApply(fun, args).copyAttr(tree)
- }
- def derivedLiteral(const: Constant): Literal[T] = tree match {
- case tree: Literal[_] if (const == tree.const) => tree
- case _ => Literal[T](const).copyAttr(tree)
- }
- def derivedNew(tpt: Tree[T]): New[T] = tree match {
- case tree: New[_] if (tpt eq tree.tpt) => tree
- case _ => New(tpt).copyAttr(tree)
- }
- def derivedPair(left: Tree[T], right: Tree[T]): Pair[T] = tree match {
- case tree: Pair[_] if (left eq tree.left) && (right eq tree.right) => tree
- case _ => Pair(left, right).copyAttr(tree)
- }
- def derivedTyped(expr: Tree[T], tpt: Tree[T]): Typed[T] = tree match {
- case tree: Typed[_] if (expr eq tree.expr) && (tpt eq tree.tpt) => tree
- case _ => Typed(expr, tpt).copyAttr(tree)
- }
- def derivedNamedArg(name: Name, arg: Tree[T]): NamedArg[T] = tree match {
- case tree: NamedArg[_] if (name == tree.name) && (arg eq tree.arg) => tree
- case _ => NamedArg(name, arg).copyAttr(tree)
- }
- def derivedAssign(lhs: Tree[T], rhs: Tree[T]): Assign[T] = tree match {
- case tree: Assign[_] if (lhs eq tree.lhs) && (rhs eq tree.rhs) => tree
- case _ => Assign(lhs, rhs).copyAttr(tree)
- }
- def derivedBlock(stats: List[Tree[T]], expr: Tree[T]): Block[T] = tree match {
- case tree: Block[_] if (stats eq tree.stats) && (expr eq tree.expr) => tree
- case _ => Block(stats, expr).copyAttr(tree)
- }
- def derivedIf(cond: Tree[T], thenp: Tree[T], elsep: Tree[T]): If[T] = tree match {
- case tree: If[_] if (cond eq tree.cond) && (thenp eq tree.thenp) && (elsep eq tree.elsep) => tree
- case _ => If(cond, thenp, elsep).copyAttr(tree)
- }
- def derivedMatch(selector: Tree[T], cases: List[CaseDef[T]]): Match[T] = tree match {
- case tree: Match[_] if (selector eq tree.selector) && (cases eq tree.cases) => tree
- case _ => Match(selector, cases).copyAttr(tree)
- }
- def derivedCaseDef(pat: Tree[T], guard: Tree[T], body: Tree[T]): CaseDef[T] = tree match {
- 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: 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)
- }
- def derivedTry(expr: Tree[T], handler: Tree[T], finalizer: Tree[T]): Try[T] = tree match {
- case tree: Try[_] if (expr eq tree.expr) && (handler eq tree.handler) && (finalizer eq tree.finalizer) => tree
- case _ => Try(expr, handler, finalizer).copyAttr(tree)
- }
- def derivedThrow(expr: Tree[T]): Throw[T] = tree match {
- case tree: Throw[_] if (expr eq tree.expr) => tree
- case _ => Throw(expr).copyAttr(tree)
- }
- def derivedSeqLiteral(elemtpt: Tree[T], elems: List[Tree[T]]): SeqLiteral[T] = tree match {
- case tree: SeqLiteral[_] if (elemtpt eq tree.elemtpt) && (elems eq tree.elems) => tree
- case _ => SeqLiteral(elemtpt, elems).copyAttr(tree)
- }
- def derivedSingletonTypeTree(ref: Tree[T]): SingletonTypeTree[T] = tree match {
- case tree: SingletonTypeTree[_] if (ref eq tree.ref) => tree
- case _ => SingletonTypeTree(ref).copyAttr(tree)
- }
- def derivedSelectFromTypeTree(qualifier: Tree[T], name: Name): SelectFromTypeTree[T] = tree match {
- case tree: SelectFromTypeTree[_] if (qualifier eq tree.qualifier) && (name == tree.name) => tree
- case _ => SelectFromTypeTree(qualifier, name).copyAttr(tree)
- }
- def derivedAndTypeTree(left: Tree[T], right: Tree[T]): AndTypeTree[T] = tree match {
- case tree: AndTypeTree[_] if (left eq tree.left) && (right eq tree.right) => tree
- case _ => AndTypeTree(left, right).copyAttr(tree)
- }
- def derivedOrTypeTree(left: Tree[T], right: Tree[T]): OrTypeTree[T] = tree match {
- case tree: OrTypeTree[_] if (left eq tree.left) && (right eq tree.right) => tree
- case _ => OrTypeTree(left, right).copyAttr(tree)
- }
- def derivedRefinedTypeTree(tpt: Tree[T], refinements: List[Tree[T]]): RefinedTypeTree[T] = tree match {
- case tree: RefinedTypeTree[_] if (tpt eq tree.tpt) && (refinements eq tree.refinements) => tree
- case _ => RefinedTypeTree(tpt, refinements).copyAttr(tree)
- }
- def derivedAppliedTypeTree(tpt: Tree[T], args: List[Tree[T]]): AppliedTypeTree[T] = tree match {
- case tree: AppliedTypeTree[_] if (tpt eq tree.tpt) && (args eq tree.args) => tree
- case _ => AppliedTypeTree(tpt, args).copyAttr(tree)
- }
- def derivedTypeBoundsTree(lo: Tree[T], hi: Tree[T]): TypeBoundsTree[T] = tree match {
- case tree: TypeBoundsTree[_] if (lo eq tree.lo) && (hi eq tree.hi) => tree
- case _ => TypeBoundsTree(lo, hi).copyAttr(tree)
- }
- def derivedBind(name: Name, body: Tree[T]): Bind[T] = tree match {
- case tree: Bind[_] if (name eq tree.name) && (body eq tree.body) => tree
- case _ => Bind(name, body).copyAttr(tree)
- }
- def derivedAlternative(trees: List[Tree[T]]): Alternative[T] = tree match {
- case tree: Alternative[_] if (trees eq tree.trees) => tree
- case _ => Alternative(trees).copyAttr(tree)
- }
- def derivedUnApply(fun: Tree[T], args: List[Tree[T]]): UnApply[T] = tree match {
- case tree: UnApply[_] if (fun eq tree.fun) && (args eq tree.args) => tree
- case _ => UnApply(fun, args).copyAttr(tree)
- }
- def derivedValDef(mods: Modifiers[T], name: TermName, tpt: Tree[T], rhs: Tree[T]): ValDef[T] = tree match {
- case tree: ValDef[_] if (mods == tree.mods) && (name == tree.name) && (tpt eq tree.tpt) && (rhs eq tree.rhs) => tree
- case _ => ValDef(mods, name, tpt, rhs).copyAttr(tree)
- }
- def derivedDefDef(mods: Modifiers[T], name: TermName, tparams: List[TypeDef[T]], vparamss: List[List[ValDef[T]]], tpt: Tree[T], rhs: Tree[T]): DefDef[T] = tree match {
- 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, 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(constr: DefDef[T], parents: List[Tree[T]], self: ValDef[T], body: List[Tree[T]]): Template[T] = tree match {
- case tree: Template[_] if (constr eq tree.constr) && (parents eq tree.parents) && (self eq tree.self) && (body eq tree.body) => tree
- case _ => Template(constr, parents, self, body).copyAttr(tree)
- }
- def derivedClassDef(mods: Modifiers[T], name: TypeName, tparams: List[TypeDef[T]], impl: Template[T]): ClassDef[T] = tree match {
- case tree: ClassDef[_] if (mods == tree.mods) && (name == tree.name) && (tparams eq tree.tparams) && (impl eq tree.impl) => tree
- case _ => ClassDef(mods, name, tparams, impl).copyAttr(tree)
- }
- def derivedImport(expr: Tree[T], selectors: List[UntypedTree]): Import[T] = tree match {
- case tree: Import[_] if (expr eq tree.expr) && (selectors eq tree.selectors) => tree
- case _ => Import(expr, selectors).copyAttr(tree)
- }
- def derivedPackageDef(pid: RefTree[T], stats: List[Tree[T]]): PackageDef[T] = tree match {
- case tree: PackageDef[_] if (pid eq tree.pid) && (stats eq tree.stats) => tree
- case _ => PackageDef(pid, stats).copyAttr(tree)
- }
- def derivedAnnotated(annot: Tree[T], arg: Tree[T]): Annotated[T] = tree match {
- case tree: Annotated[_] if (annot eq tree.annot) && (arg eq tree.arg) => tree
- case _ => Annotated(annot, arg).copyAttr(tree)
- }
- def derivedSharedTree(shared: Tree[T]): SharedTree[T] = tree match {
- case tree: SharedTree[_] if (shared eq tree.shared) => tree
- case _ => SharedTree(shared).copyAttr(tree)
- }
- }
-
- abstract class FullTreeTransformer[T >: Untyped, C] {
- var sharedMemo: Map[SharedTree[T], SharedTree[T]] = Map()
-
- def transform(tree: Tree[T], c: C): Tree[T] = tree match {
- case Ident(name) =>
- finishIdent(tree, tree, c, plugins)
- case Select(qualifier, name) =>
- finishSelect(tree.derivedSelect(transform(qualifier, c), name), tree, c, plugins)
- case This(qual) =>
- finishThis(tree, tree, c, plugins)
- case Super(qual, mix) =>
- finishSuper(tree.derivedSuper(transform(qual, c), mix), tree, c, plugins)
- case Apply(fun, args) =>
- finishApply(tree.derivedApply(transform(fun, c), transform(args, c)), tree, c, plugins)
- case TypeApply(fun, args) =>
- finishTypeApply(tree.derivedTypeApply(transform(fun, c), transform(args, c)), tree, c, plugins)
- case Literal(const) =>
- finishLiteral(tree, tree, c, plugins)
- case New(tpt) =>
- finishNew(tree.derivedNew(transform(tpt, c)), tree, c, plugins)
- case Pair(left, right) =>
- finishPair(tree.derivedPair(transform(left, c), transform(right, c)), tree, c, plugins)
- case Typed(expr, tpt) =>
- finishTyped(tree.derivedTyped(transform(expr, c), transform(tpt, c)), tree, c, plugins)
- case NamedArg(name, arg) =>
- finishNamedArg(tree.derivedNamedArg(name, transform(arg, c)), tree, c, plugins)
- case Assign(lhs, rhs) =>
- finishAssign(tree.derivedAssign(transform(lhs, c), transform(rhs, c)), tree, c, plugins)
- case Block(stats, expr) =>
- finishBlock(tree.derivedBlock(transform(stats, c), transform(expr, c)), tree, c, plugins)
- case If(cond, thenp, elsep) =>
- finishIf(tree.derivedIf(transform(cond, c), transform(thenp, c), transform(elsep, c)), tree, c, plugins)
- case Match(selector, cases) =>
- finishMatch(tree.derivedMatch(transform(selector, c), transformSub(cases, c)), tree, c, plugins)
- 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), transform(from, c)), tree, c, plugins)
- case Try(block, handler, finalizer) =>
- finishTry(tree.derivedTry(transform(block, c), transform(handler, c), transform(finalizer, c)), tree, c, plugins)
- case Throw(expr) =>
- finishThrow(tree.derivedThrow(transform(expr, c)), tree, c, plugins)
- case SeqLiteral(elemtpt, elems) =>
- finishSeqLiteral(tree.derivedSeqLiteral(transform(elemtpt, c), transform(elems, c)), tree, c, plugins)
- case TypeTree(original) =>
- finishTypeTree(tree, tree, c, plugins)
- case SingletonTypeTree(ref) =>
- finishSingletonTypeTree(tree.derivedSingletonTypeTree(transform(ref, c)), tree, c, plugins)
- case SelectFromTypeTree(qualifier, name) =>
- finishSelectFromTypeTree(tree.derivedSelectFromTypeTree(transform(qualifier, c), name), tree, c, plugins)
- case AndTypeTree(left, right) =>
- finishAndTypeTree(tree.derivedAndTypeTree(transform(left, c), transform(right, c)), tree, c, plugins)
- case OrTypeTree(left, right) =>
- finishOrTypeTree(tree.derivedOrTypeTree(transform(left, c), transform(right, c)), tree, c, plugins)
- case RefinedTypeTree(tpt, refinements) =>
- finishRefinedTypeTree(tree.derivedRefinedTypeTree(transform(tpt, c), transformSub(refinements, c)), tree, c, plugins)
- case AppliedTypeTree(tpt, args) =>
- finishAppliedTypeTree(tree.derivedAppliedTypeTree(transform(tpt, c), transform(args, c)), tree, c, plugins)
- case TypeBoundsTree(lo, hi) =>
- finishTypeBoundsTree(tree.derivedTypeBoundsTree(transform(lo, c), transform(hi, c)), tree, c, plugins)
- case Bind(name, body) =>
- finishBind(tree.derivedBind(name, transform(body, c)), tree, c, plugins)
- case Alternative(trees) =>
- finishAlternative(tree.derivedAlternative(transform(trees, c)), tree, c, plugins)
- case UnApply(fun, args) =>
- finishUnApply(tree.derivedUnApply(transform(fun, c), transform(args, c)), tree, c, plugins)
- case ValDef(mods, name, tpt, rhs) =>
- 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, tparams, rhs) =>
- finishTypeDef(tree.derivedTypeDef(mods, name, transformSub(tparams, c), transform(rhs, c)), tree, c, plugins)
- case Template(constr, parents, self, body) =>
- finishTemplate(tree.derivedTemplate(transformSub(constr, c), transform(parents, c), transformSub(self, c), transform(body, c)), tree, c, plugins)
- case ClassDef(mods, name, tparams, impl) =>
- finishClassDef(tree.derivedClassDef(mods, name, transformSub(tparams, c), transformSub(impl, c)), tree, c, plugins)
- case Import(expr, selectors) =>
- finishImport(tree.derivedImport(transform(expr, c), selectors), tree, c, plugins)
- case PackageDef(pid, stats) =>
- finishPackageDef(tree.derivedPackageDef(transformSub(pid, c), transform(stats, c)), tree, c, plugins)
- case Annotated(annot, arg) =>
- finishAnnotated(tree.derivedAnnotated(transform(annot, c), transform(arg, c)), tree, c, plugins)
- case EmptyTree() =>
- finishEmptyTree(tree, tree, c, plugins)
- case tree @ SharedTree(shared) =>
- finishSharedTree(
- sharedMemo get tree match {
- case Some(tree1) => tree1
- case None =>
- val tree1 = tree.derivedSharedTree(transform(shared, c))
- sharedMemo = sharedMemo.updated(tree, tree1)
- tree1
- },
- tree, c, plugins)
- }
- def transform(trees: List[Tree[T]], c: C): List[Tree[T]] =
- trees mapConserve (transform(_, c))
- def transformSub(tree: Tree[T], c: C): tree.ThisTree[T] =
- transform(tree, c).asInstanceOf[tree.ThisTree[T]]
- def transformSub[TT <: Tree[T]](trees: List[TT], c: C): List[TT] =
- transform(trees, c).asInstanceOf[List[TT]]
-
- type Plugins >: Null
- def plugins: Plugins = null
-
- def finishIdent(tree: Tree[T], old: Tree[T], c: C, plugins: Plugins) = tree
- def finishSelect(tree: Tree[T], old: Tree[T], c: C, plugins: Plugins) = tree
- def finishThis(tree: Tree[T], old: Tree[T], c: C, plugins: Plugins) = tree
- def finishSuper(tree: Tree[T], old: Tree[T], c: C, plugins: Plugins) = tree
- def finishApply(tree: Tree[T], old: Tree[T], c: C, plugins: Plugins) = tree
- def finishTypeApply(tree: Tree[T], old: Tree[T], c: C, plugins: Plugins) = tree
- def finishLiteral(tree: Tree[T], old: Tree[T], c: C, plugins: Plugins) = tree
- def finishNew(tree: Tree[T], old: Tree[T], c: C, plugins: Plugins) = tree
- def finishPair(tree: Tree[T], old: Tree[T], c: C, plugins: Plugins) = tree
- def finishTyped(tree: Tree[T], old: Tree[T], c: C, plugins: Plugins) = tree
- def finishNamedArg(tree: Tree[T], old: Tree[T], c: C, plugins: Plugins) = tree
- def finishAssign(tree: Tree[T], old: Tree[T], c: C, plugins: Plugins) = tree
- def finishFunction(tree: Tree[T], old: Tree[T], c: C, plugins: Plugins) = tree
- def finishBlock(tree: Tree[T], old: Tree[T], c: C, plugins: Plugins) = tree
- def finishIf(tree: Tree[T], old: Tree[T], c: C, plugins: Plugins) = tree
- def finishMatch(tree: Tree[T], old: Tree[T], c: C, plugins: Plugins) = tree
- def finishCaseDef(tree: Tree[T], old: Tree[T], c: C, plugins: Plugins) = tree
- def finishReturn(tree: Tree[T], old: Tree[T], c: C, plugins: Plugins) = tree
- def finishTry(tree: Tree[T], old: Tree[T], c: C, plugins: Plugins) = tree
- def finishThrow(tree: Tree[T], old: Tree[T], c: C, plugins: Plugins) = tree
- def finishSeqLiteral(tree: Tree[T], old: Tree[T], c: C, plugins: Plugins) = tree
- def finishTypeTree(tree: Tree[T], old: Tree[T], c: C, plugins: Plugins) = tree
- def finishSingletonTypeTree(tree: Tree[T], old: Tree[T], c: C, plugins: Plugins) = tree
- def finishSelectFromTypeTree(tree: Tree[T], old: Tree[T], c: C, plugins: Plugins) = tree
- def finishAndTypeTree(tree: Tree[T], old: Tree[T], c: C, plugins: Plugins) = tree
- def finishOrTypeTree(tree: Tree[T], old: Tree[T], c: C, plugins: Plugins) = tree
- def finishRefinedTypeTree(tree: Tree[T], old: Tree[T], c: C, plugins: Plugins) = tree
- def finishAppliedTypeTree(tree: Tree[T], old: Tree[T], c: C, plugins: Plugins) = tree
- def finishTypeBoundsTree(tree: Tree[T], old: Tree[T], c: C, plugins: Plugins) = tree
- def finishBind(tree: Tree[T], old: Tree[T], c: C, plugins: Plugins) = tree
- def finishAlternative(tree: Tree[T], old: Tree[T], c: C, plugins: Plugins) = tree
- def finishUnApply(tree: Tree[T], old: Tree[T], c: C, plugins: Plugins) = tree
- def finishValDef(tree: Tree[T], old: Tree[T], c: C, plugins: Plugins) = tree
- def finishDefDef(tree: Tree[T], old: Tree[T], c: C, plugins: Plugins) = tree
- def finishTypeDef(tree: Tree[T], old: Tree[T], c: C, plugins: Plugins) = tree
- def finishTemplate(tree: Tree[T], old: Tree[T], c: C, plugins: Plugins) = tree
- def finishClassDef(tree: Tree[T], old: Tree[T], c: C, plugins: Plugins) = tree
- def finishImport(tree: Tree[T], old: Tree[T], c: C, plugins: Plugins) = tree
- def finishPackageDef(tree: Tree[T], old: Tree[T], c: C, plugins: Plugins) = tree
- def finishAnnotated(tree: Tree[T], old: Tree[T], c: C, plugins: Plugins) = tree
- def finishEmptyTree(tree: Tree[T], old: Tree[T], c: C, plugins: Plugins) = tree
- def finishSharedTree(tree: Tree[T], old: Tree[T], c: C, plugins: Plugins) = tree
- }
-
- abstract class TreeTransformer[T >: Untyped] {
- var sharedMemo: Map[SharedTree[T], SharedTree[T]] = Map()
-
- def transform(tree: Tree[T]): Tree[T] = tree match {
- case Ident(name) =>
- tree
- case Select(qualifier, name) =>
- tree.derivedSelect(transform(qualifier), name)
- case This(qual) =>
- tree
- case Super(qual, mix) =>
- tree.derivedSuper(transform(qual), mix)
- case Apply(fun, args) =>
- tree.derivedApply(transform(fun), transform(args))
- case TypeApply(fun, args) =>
- tree.derivedTypeApply(transform(fun), transform(args))
- case Literal(const) =>
- tree
- case New(tpt) =>
- tree.derivedNew(transform(tpt))
- case Pair(left, right) =>
- tree.derivedPair(transform(left), transform(right))
- case Typed(expr, tpt) =>
- tree.derivedTyped(transform(expr), transform(tpt))
- case NamedArg(name, arg) =>
- tree.derivedNamedArg(name, transform(arg))
- case Assign(lhs, rhs) =>
- tree.derivedAssign(transform(lhs), transform(rhs))
- case Block(stats, expr) =>
- tree.derivedBlock(transform(stats), transform(expr))
- case If(cond, thenp, elsep) =>
- tree.derivedIf(transform(cond), transform(thenp), transform(elsep))
- case Match(selector, cases) =>
- tree.derivedMatch(transform(selector), transformSub(cases))
- case CaseDef(pat, guard, body) =>
- tree.derivedCaseDef(transform(pat), transform(guard), transform(body))
- case Return(expr, from) =>
- tree.derivedReturn(transform(expr), transformSub(from))
- case Try(block, handler, finalizer) =>
- tree.derivedTry(transform(block), transform(handler), transform(finalizer))
- case Throw(expr) =>
- tree.derivedThrow(transform(expr))
- case SeqLiteral(elemtpt, elems) =>
- tree.derivedSeqLiteral(transform(elemtpt), transform(elems))
- case TypeTree(original) =>
- tree
- case SingletonTypeTree(ref) =>
- tree.derivedSingletonTypeTree(transform(ref))
- case SelectFromTypeTree(qualifier, name) =>
- tree.derivedSelectFromTypeTree(transform(qualifier), name)
- case AndTypeTree(left, right) =>
- tree.derivedAndTypeTree(transform(left), transform(right))
- case OrTypeTree(left, right) =>
- tree.derivedOrTypeTree(transform(left), transform(right))
- case RefinedTypeTree(tpt, refinements) =>
- tree.derivedRefinedTypeTree(transform(tpt), transformSub(refinements))
- case AppliedTypeTree(tpt, args) =>
- tree.derivedAppliedTypeTree(transform(tpt), transform(args))
- case TypeBoundsTree(lo, hi) =>
- tree.derivedTypeBoundsTree(transform(lo), transform(hi))
- case Bind(name, body) =>
- tree.derivedBind(name, transform(body))
- case Alternative(trees) =>
- tree.derivedAlternative(transform(trees))
- case UnApply(fun, args) =>
- tree.derivedUnApply(transform(fun), transform(args))
- case ValDef(mods, name, tpt, rhs) =>
- 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, tparams, rhs) =>
- tree.derivedTypeDef(mods, name, transformSub(tparams), transform(rhs))
- case Template(constr, parents, self, body) =>
- tree.derivedTemplate(transformSub(constr), transform(parents), transformSub(self), transform(body))
- case ClassDef(mods, name, tparams, impl) =>
- tree.derivedClassDef(mods, name, transformSub(tparams), transformSub(impl))
- case Import(expr, selectors) =>
- tree.derivedImport(transform(expr), selectors)
- case PackageDef(pid, stats) =>
- tree.derivedPackageDef(transformSub(pid), transform(stats))
- case Annotated(annot, arg) =>
- tree.derivedAnnotated(transform(annot), transform(arg))
- case EmptyTree() =>
- tree
- case tree @ SharedTree(shared) =>
- sharedMemo get tree match {
- case Some(tree1) => tree1
- case None =>
- val tree1 = tree.derivedSharedTree(transform(shared))
- sharedMemo = sharedMemo.updated(tree, tree1)
- tree1
- }
- }
- def transform(trees: List[Tree[T]]): List[Tree[T]] =
- trees mapConserve (transform(_))
- def transformSub(tree: Tree[T]): tree.ThisTree[T] =
- transform(tree).asInstanceOf[tree.ThisTree[T]]
- def transformSub[TT <: Tree[T]](trees: List[TT]): List[TT] =
- transform(trees).asInstanceOf[List[TT]]
- }
-
- abstract class TreeAccumulator[X, T >: Untyped] extends ((X, Tree[T]) => X) {
- var sharedMemo: Map[SharedTree[T], X] = Map()
- def apply(x: X, tree: Tree[T]): X
- def apply(x: X, trees: List[Tree[T]]): X = (x /: trees)(apply)
- def foldOver(x: X, tree: Tree[T]): X = tree match {
- case Ident(name) =>
- x
- case Select(qualifier, name) =>
- this(x, qualifier)
- case This(qual) =>
- x
- case Super(qual, mix) =>
- this(x, qual)
- case Apply(fun, args) =>
- this(this(x, fun), args)
- case TypeApply(fun, args) =>
- this(this(x, fun), args)
- case Literal(const) =>
- x
- case New(tpt) =>
- this(x, tpt)
- case Pair(left, right) =>
- this(this(x, left), right)
- case Typed(expr, tpt) =>
- this(this(x, expr), tpt)
- case NamedArg(name, arg) =>
- this(x, arg)
- case Assign(lhs, rhs) =>
- this(this(x, lhs), rhs)
- case Block(stats, expr) =>
- this(this(x, stats), expr)
- case If(cond, thenp, elsep) =>
- this(this(this(x, cond), thenp), elsep)
- case Match(selector, cases) =>
- this(this(x, selector), cases)
- case CaseDef(pat, guard, body) =>
- this(this(this(x, pat), guard), body)
- case Return(expr, from) =>
- this(this(x, expr), from)
- case Try(block, handler, finalizer) =>
- this(this(this(x, block), handler), finalizer)
- case Throw(expr) =>
- this(x, expr)
- case SeqLiteral(elemtpt, elems) =>
- this(this(x, elemtpt), elems)
- case TypeTree(original) =>
- x
- case SingletonTypeTree(ref) =>
- this(x, ref)
- case SelectFromTypeTree(qualifier, name) =>
- this(x, qualifier)
- case AndTypeTree(left, right) =>
- this(this(x, left), right)
- case OrTypeTree(left, right) =>
- this(this(x, left), right)
- case RefinedTypeTree(tpt, refinements) =>
- this(this(x, tpt), refinements)
- case AppliedTypeTree(tpt, args) =>
- this(this(x, tpt), args)
- case TypeBoundsTree(lo, hi) =>
- this(this(x, lo), hi)
- case Bind(name, body) =>
- this(x, body)
- case Alternative(trees) =>
- this(x, trees)
- case UnApply(fun, args) =>
- this(this(x, fun), args)
- case ValDef(mods, name, tpt, rhs) =>
- 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, tparams, rhs) =>
- this(this(x, tparams), rhs)
- case Template(constr, parents, self, body) =>
- this(this(this(this(x, constr), parents), self), body)
- case ClassDef(mods, name, tparams, impl) =>
- this(this(x, tparams), impl)
- case Import(expr, selectors) =>
- this(x, expr)
- case PackageDef(pid, stats) =>
- this(this(x, pid), stats)
- case Annotated(annot, arg) =>
- this(this(x, annot), arg)
- case EmptyTree() =>
- x
- case tree @ SharedTree(shared) =>
- sharedMemo get tree match {
- case Some(x1) => x1
- case None =>
- val x1 = this(x, shared)
- sharedMemo = sharedMemo.updated(tree, x1)
- x1
- }
- }
- }
-
- /** Fold `f` over all tree nodes, in depth-first, prefix order */
- class DeepFolder[X, T >: Untyped](f: (X, Tree[T]) => X) extends TreeAccumulator[X, T] {
- def apply(x: X, tree: Tree[T]): X = foldOver(f(x, tree), tree)
- }
-
- /** Fold `f` over all tree nodes, in depth-first, prefix order, but don't visit
- * subtrees where `f` returns a different result for the root, i.e. `f(x, root) ne x`.
- */
- class ShallowFolder[X, T >: Untyped](f: (X, Tree[T]) => X) extends TreeAccumulator[X, T] {
- def apply(x: X, tree: Tree[T]): X = {
- val x1 = f(x, tree)
- if (x1.asInstanceOf[AnyRef] ne x1.asInstanceOf[AnyRef]) x1
- else foldOver(x1, tree)
- }
- }
-}
diff --git a/src/dotty/tools/dotc/core/TypeComparers.scala b/src/dotty/tools/dotc/core/TypeComparers.scala
index 9d109b724..7dd874325 100644
--- a/src/dotty/tools/dotc/core/TypeComparers.scala
+++ b/src/dotty/tools/dotc/core/TypeComparers.scala
@@ -1,4 +1,5 @@
-package dotty.tools.dotc.core
+package dotty.tools
+package dotc.core
import Types._, Contexts._, Symbols._, Flags._
import collection.mutable
diff --git a/src/dotty/tools/dotc/core/TypedTrees.scala b/src/dotty/tools/dotc/core/TypedTrees.scala
deleted file mode 100644
index 2ded92920..000000000
--- a/src/dotty/tools/dotc/core/TypedTrees.scala
+++ /dev/null
@@ -1,636 +0,0 @@
-package dotty.tools.dotc
-package core
-
-import util.Positions._, Types._, Contexts._, Constants._, Names._, Flags._
-import SymDenotations._, Symbols._, StdNames._, Annotations._
-
-object TypedTrees {
-
- object tpd extends Trees.Instance[Type] {
-
- def Modifiers(sym: Symbol)(implicit ctx: Context): Modifiers = Trees.Modifiers[Type](
- sym.flags & ModifierFlags,
- if (sym.privateWithin.exists) sym.privateWithin.asType.name else tpnme.EMPTY,
- sym.annotations map (_.tree))
-
- def Ident(tp: NamedType)(implicit ctx: Context): Ident =
- Trees.Ident(tp.name).withType(tp).checked
-
- def Select(pre: Tree, tp: NamedType)(implicit ctx: Context): Select =
- Trees.Select(pre, tp.name).withType(tp).checked
-
- def This(cls: ClassSymbol)(implicit ctx: Context): This =
- Trees.This(cls.name).withType(cls.thisType).checked
-
- def Super(qual: Tree, mix: TypeName)(implicit ctx: Context): Super = {
- val owntype =
- if (mix.isEmpty) ctx.glb(qual.tpe.parents)
- else {
- val mixParents = qual.tpe.parents filter (_.name == mix)
- check(mixParents.length == 1)
- mixParents.head
- }
- Trees.Super(qual, mix).withType(SuperType(qual.tpe, owntype)).checked
- }
-
- def Apply(fn: Tree, args: List[Tree])(implicit ctx: Context): Apply = {
- val owntype = fn.tpe.widen match {
- case fntpe @ MethodType(pnames, ptypes) =>
- check(sameLength(ptypes, args), s"${fn.show}: ${fntpe.show} to ${args.map(_.show).mkString(", ")}")
- fntpe.instantiate(args map (_.tpe))
- case _ =>
- check(false)
- ErrorType
- }
- Trees.Apply(fn, args).withType(owntype).checked
- }
-
- def TypeApply(fn: Tree, args: List[Tree])(implicit ctx: Context): TypeApply = {
- val owntype = fn.tpe.widen match {
- case fntpe @ PolyType(pnames) =>
- check(sameLength(pnames, args))
- fntpe.instantiate(args map (_.tpe))
- case _ =>
- check(false)
- ErrorType
- }
- Trees.TypeApply(fn, args).withType(owntype).checked
- }
-
- def Literal(const: Constant)(implicit ctx: Context): Literal =
- Trees.Literal(const).withType(const.tpe).checked
-
- def New(tp: Type)(implicit ctx: Context): New =
- Trees.New(TypeTree(tp)).withType(tp).checked
-
- def Pair(left: Tree, right: Tree)(implicit ctx: Context): Pair =
- Trees.Pair(left, right).withType(defn.PairType.appliedTo(left.tpe, right.tpe)).checked
-
- def Typed(expr: Tree, tpt: Tree)(implicit ctx: Context): Typed =
- Trees.Typed(expr, tpt).withType(tpt.tpe).checked
-
- def NamedArg(name: TermName, arg: Tree)(implicit ctx: Context) =
- Trees.NamedArg(name, arg).withType(arg.tpe).checked
-
- def Assign(lhs: Tree, rhs: Tree)(implicit ctx: Context): Assign =
- Trees.Assign(lhs, rhs).withType(defn.UnitType).checked
-
- def Block(stats: List[Tree], expr: Tree)(implicit ctx: Context): Block = {
- lazy val locals = localSyms(stats).toSet
- val blk = Trees.Block(stats, expr)
- def widen(tp: Type): Type = tp match {
- case tp: TermRef if locals contains tp.symbol =>
- widen(tp.info)
- case _ => tp
- }
- blk.withType(widen(expr.tpe))
- }
-
- def If(cond: Tree, thenp: Tree, elsep: Tree)(implicit ctx: Context): If =
- Trees.If(cond, thenp, elsep).withType(thenp.tpe | elsep.tpe).checked
-
- def Match(selector: Tree, cases: List[CaseDef])(implicit ctx: Context): Match =
- Trees.Match(selector, cases).withType(ctx.lub(cases map (_.body.tpe))).checked
-
- def CaseDef(pat: Tree, guard: Tree, body: Tree)(implicit ctx: Context): CaseDef =
- Trees.CaseDef(pat, guard, body).withType(body.tpe).checked
-
- def Return(expr: Tree, from: Ident)(implicit ctx: Context): Return =
- Trees.Return(expr, from).withType(defn.NothingType).checked
-
- def Try(block: Tree, handler: Tree, finalizer: Tree)(implicit ctx: Context): Try =
- Trees.Try(block, handler, finalizer).withType(block.tpe | handler.tpe).checked
-
- def Throw(expr: Tree)(implicit ctx: Context): Throw =
- Trees.Throw(expr).withType(defn.NothingType).checked
-
- def SeqLiteral(elemtpt: Tree, elems: List[Tree])(implicit ctx: Context): SeqLiteral =
- Trees.SeqLiteral(elemtpt, elems).withType(defn.RepeatedParamType.appliedTo(elemtpt.tpe)).checked
-
- def SeqLiteral(elems: List[Tree])(implicit ctx: Context): SeqLiteral =
- SeqLiteral(TypeTree(ctx.lub(elems map (_.tpe))), elems)
-
- def TypeTree(tp: Type, original: Tree = EmptyTree)(implicit ctx: Context): TypeTree =
- Trees.TypeTree(original).withType(tp).checked
-
- def SingletonTypeTree(ref: Tree)(implicit ctx: Context): SingletonTypeTree =
- Trees.SingletonTypeTree(ref).withType(ref.tpe).checked
-
- def SelectFromTypeTree(qualifier: Tree, tp: NamedType)(implicit ctx: Context): SelectFromTypeTree =
- Trees.SelectFromTypeTree(qualifier, tp.name).withType(tp).checked
-
- def AndTypeTree(left: Tree, right: Tree)(implicit ctx: Context): AndTypeTree =
- Trees.AndTypeTree(left, right).withType(left.tpe & right.tpe).checked
-
- def OrTypeTree(left: Tree, right: Tree)(implicit ctx: Context): OrTypeTree =
- Trees.OrTypeTree(left, right).withType(left.tpe | right.tpe).checked
-
- def RefinedTypeTree(tpt: Tree, refinements: List[DefTree])(implicit ctx: Context): RefinedTypeTree = {
- def refineType(tp: Type, refinement: Symbol): Type =
- RefinedType(tp, refinement.name, refinement.info)
- Trees.RefinedTypeTree(tpt, refinements)
- .withType((tpt.tpe /: (refinements map (_.symbol)))(refineType)).checked
- }
-
- def refineType(tp: Type, refinement: Symbol)(implicit ctx: Context): Type =
- RefinedType(tp, refinement.name, refinement.info)
-
- def AppliedTypeTree(tpt: Tree, args: List[Tree])(implicit ctx: Context): AppliedTypeTree =
- Trees.AppliedTypeTree(tpt, args).withType(tpt.tpe.appliedTo(args map (_.tpe))).checked
-
- def TypeBoundsTree(lo: Tree, hi: Tree)(implicit ctx: Context): TypeBoundsTree =
- Trees.TypeBoundsTree(lo, hi).withType(TypeBounds(lo.tpe, hi.tpe)).checked
-
- def Bind(sym: TermSymbol, body: Tree)(implicit ctx: Context): Bind =
- Trees.Bind(sym.name, body).withType(refType(sym)).checked
-
- def Alternative(trees: List[Tree])(implicit ctx: Context): Alternative =
- Trees.Alternative(trees).withType(ctx.lub(trees map (_.tpe))).checked
-
- def UnApply(fun: Tree, args: List[Tree])(implicit ctx: Context): UnApply = {
- val owntype = fun.tpe.widen match {
- case MethodType(_, paramType :: Nil) => paramType
- case _ => check(false); ErrorType
- }
- Trees.UnApply(fun, args).withType(owntype).checked
- }
-
- def ValDef(sym: TermSymbol, rhs: Tree = EmptyTree)(implicit ctx: Context): ValDef =
- Trees.ValDef(Modifiers(sym), sym.name, TypeTree(sym.info), rhs).withType(refType(sym)).checked
-
- def DefDef(sym: TermSymbol, rhs: Tree = EmptyTree)(implicit ctx: Context): DefDef = {
-
- val (tparams, mtp) = sym.info match {
- case tp: PolyType =>
- val tparams = ctx.newTypeParams(sym, tp.paramNames, EmptyFlags, tp.instantiateBounds)
- (tparams, tp.instantiate(tparams map (_.typeConstructor)))
- case tp => (Nil, tp)
- }
-
- def valueParamss(tp: Type): (List[List[TermSymbol]], Type) = tp match {
- case tp @ MethodType(paramNames, paramTypes) =>
- def valueParam(name: TermName, info: Type): TermSymbol =
- ctx.newSymbol(sym, name, TermParam, info)
- val params = (paramNames, paramTypes).zipped.map(valueParam)
- val (paramss, rtp) = valueParamss(tp.instantiate(params map (_.typeConstructor)))
- (params :: paramss, rtp)
- case tp => (Nil, tp)
- }
- val (vparamss, rtp) = valueParamss(mtp)
-
- Trees.DefDef(
- Modifiers(sym), sym.name, tparams map TypeDef,
- vparamss map (_ map (ValDef(_))), TypeTree(rtp), rhs)
- .withType(refType(sym)).checked
- }
-
- def TypeDef(sym: TypeSymbol)(implicit ctx: Context): TypeDef =
- Trees.TypeDef(Modifiers(sym), sym.name, Nil, TypeTree(sym.info)) // !!! fill in typeParams
- .withType(refType(sym)).checked
-
- def ClassDef(cls: ClassSymbol, typeParams: List[TypeSymbol], constr: DefDef, body: List[Tree])(implicit ctx: Context): ClassDef = {
- val parents = cls.info.parents map (TypeTree(_))
- val selfType =
- if (cls.classInfo.optSelfType.exists) ValDef(ctx.newSelfSym(cls))
- else EmptyValDef
- def isOwnTypeParamAccessor(stat: Tree) =
- (stat.symbol is TypeParam) && stat.symbol.owner == cls
- val (tparamAccessors, rest) = body partition isOwnTypeParamAccessor
- val tparams =
- (typeParams map TypeDef) ++
- (tparamAccessors collect {
- case td: TypeDef if !(typeParams contains td.symbol) => td
- })
- val findLocalDummy = new FindLocalDummyAccumulator(cls)
- val localDummy = ((NoSymbol: Symbol) /: body)(findLocalDummy)
- .orElse(ctx.newLocalDummy(cls))
- val impl = Trees.Template(constr, parents, selfType, rest)
- .withType(refType(localDummy)).checked
- Trees.ClassDef(Modifiers(cls), cls.name, tparams, impl)
- .withType(refType(cls)).checked
- }
-
- def Import(expr: Tree, selectors: List[Trees.UntypedTree])(implicit ctx: Context): Import =
- Trees.Import(expr, selectors).withType(refType(ctx.newImportSymbol(SharedTree(expr)))).checked
-
- def PackageDef(pid: RefTree, stats: List[Tree])(implicit ctx: Context): PackageDef =
- Trees.PackageDef(pid, stats).withType(refType(pid.symbol)).checked
-
- def Annotated(annot: Tree, arg: Tree)(implicit ctx: Context): Annotated =
- Trees.Annotated(annot, arg).withType(AnnotatedType(Annotation(annot), arg.tpe)).checked
-
- val EmptyTree: Tree = Trees.EmptyTree[Type]
-
- val EmptyValDef: ValDef = Trees.EmptyValDef[Type]
-
- def SharedTree(tree: Tree): SharedTree =
- Trees.SharedTree(tree).withType(tree.tpe)
-
- 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 -------
-
- /** A tree representing the same reference as the given type */
- def ref(tp: NamedType)(implicit ctx: Context): NameTree =
- if (tp.symbol.isStatic) Ident(tp)
- else tp.prefix match {
- case pre: TermRef => Select(ref(pre), tp)
- case pre => SelectFromTypeTree(TypeTree(pre), tp)
- } // no checks necessary
-
- 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 =
- Apply(
- Select(
- New(tp),
- TermRef.withSym(tp.normalizedPrefix, tp.typeSymbol.primaryConstructor.asTerm)),
- args)
-
- /** An object def
- *
- * object obs extends parents { decls }
- *
- * gets expanded to
- *
- * <module> lazy val obj = {
- * class obj$ extends parents { this: obj.type => decls }
- * new obj$
- * }
- *
- * What's interesting here is that the block is well typed
- * (because class obj$ is hoistable), but the type of the `obj` val is
- * not expressible. What needs to happen in general when
- * inferring the type of a val from its RHS, is: if the type contains
- * a class that has the val itself as owner, then that class
- * is remapped to have the val's owner as owner. Remapping could be
- * done by cloning the class with the new owner and substituting
- * everywhere in the tree. We know that remapping is safe
- * because the only way a local class can appear in the RHS of a val is
- * by being hoisted outside of a block, and the necessary checks are
- * done at this point already.
- *
- * On the other hand, for method result type inference, if the type of
- * the RHS of a method contains a class owned by the method, this would be
- * an error.
- */
- def ModuleDef(sym: TermSymbol, body: List[Tree])(implicit ctx: Context): tpd.TempTrees = {
- val modcls = sym.moduleClass.asClass
- val constr = DefDef(modcls.primaryConstructor.asTerm, EmptyTree)
- val clsdef = ClassDef(modcls, Nil, constr, body)
- val valdef = ValDef(sym, New(modcls.typeConstructor))
- TempTrees(valdef :: clsdef :: Nil)
- }
-
- /** A function def
- *
- * vparams => expr
- *
- * gets expanded to
- *
- * { def $anonfun(vparams) = expr; $anonfun: pt }
- *
- * where pt is the target type of the expression (FunctionN) unless
- * otherwise specified.
- */
- def Function(meth: TermSymbol, body: Tree, target: Type = NoType)(implicit ctx: Context): Block = {
- val funtpe =
- if (target.exists) target
- else meth.info match {
- case mt @ MethodType(_, formals) =>
- assert(!mt.isDependent)
- defn.FunctionType(formals, mt.resultType)
- }
- Block(
- DefDef(meth, body) :: Nil,
- Typed(Ident(TermRef.withSym(NoPrefix, meth)), TypeTree(funtpe)))
- }
-
- private class FindLocalDummyAccumulator(cls: ClassSymbol)(implicit ctx: Context) extends TreeAccumulator[Symbol] {
- def apply(sym: Symbol, tree: Tree) =
- if (sym.exists) sym
- else if (tree.isDef) {
- val owner = tree.symbol.owner
- if (owner.isLocalDummy && owner.owner == cls) owner
- else if (owner == cls) foldOver(sym, tree)
- else sym
- } else foldOver(sym, tree)
- }
- }
-
- import Trees._
-
- def check(p: Boolean, msg: => String = "")(implicit ctx: Context): Unit = assert(p, msg)
-
- def checkTypeArg(arg: tpd.Tree, bounds: TypeBounds)(implicit ctx: Context): Unit = {
- check(arg.isValueType)
- check(bounds contains arg.tpe)
- }
-
- def checkType(tree: tpd.Tree)(implicit ctx: Context): Unit = tree match {
- case Ident(name) =>
- case Select(qualifier, name) =>
- check(qualifier.isValue)
- check(qualifier.tpe =:= tree.tpe.normalizedPrefix)
- val denot = qualifier.tpe.member(name)
- check(denot.exists)
- check(denot.hasAltWith(_.symbol == tree.symbol))
- case This(cls) =>
- case Super(qual, mixin) =>
- check(qual.isValue)
- val cls = qual.tpe.typeSymbol
- check(cls.isClass)
- case Apply(fn, args) =>
- def checkArg(arg: tpd.Tree, name: Name, formal: Type): Unit = {
- arg match {
- case NamedArg(argName, _) =>
- check(argName == name)
- case SeqLiteral(_, _) =>
- check(defn.RepeatedParamClasses contains formal.typeSymbol)
- case _ =>
- check(arg.isValue)
- }
- check(arg.tpe <:< formal)
- }
- val MethodType(paramNames, paramTypes) = fn.tpe.widen // checked already at construction
- (args, paramNames, paramTypes).zipped foreach checkArg
- case TypeApply(fn, args) =>
- val pt @ PolyType(_) = fn.tpe.widen // checked already at construction
- (args, pt.instantiateBounds(args map (_.tpe))).zipped foreach checkTypeArg
- case Literal(const: Constant) =>
- case New(tpt) =>
- check(tpt.isValueType)
- val cls = tpt.tpe.typeSymbol
- check(cls.isClass)
- check(!(cls is AbstractOrTrait))
- case Pair(left, right) =>
- check(left.isValue)
- check(right.isValue)
- case Typed(expr, tpt) =>
- check(tpt.isValueType)
- expr.tpe.widen match {
- case tp: MethodType =>
- val cls = tpt.tpe.typeSymbol
- check(cls.isClass)
- check((cls is Trait) ||
- cls.primaryConstructor.info.paramTypess.flatten.isEmpty)
- val absMembers = tpt.tpe.abstractTermMembers
- check(absMembers.size == 1)
- check(tp <:< absMembers.head.info)
- case _ =>
- check(expr.isValueOrPattern)
- check(expr.tpe <:< tpt.tpe)
- }
- case NamedArg(name, arg) =>
- case Assign(lhs, rhs) =>
- check(lhs.isValue); check(rhs.isValue)
- lhs.tpe match {
- case ltpe: TermRef =>
- check(ltpe.symbol is Mutable)
- case _ =>
- check(false)
- }
- check(rhs.tpe <:< lhs.tpe.widen)
- case Block(stats, expr) =>
- var hoisted: Set[Symbol] = Set()
- lazy val locals = localSyms(stats).toSet
- check(expr.isValue)
- def isNonLocal(sym: Symbol): Boolean =
- !(locals contains sym) || isHoistableClass(sym)
- def isHoistableClass(sym: Symbol) =
- sym.isClass && {
- (hoisted contains sym) || {
- hoisted += sym
- noLeaksInClass(sym.asClass)
- }
- }
- def noLeaksIn(tp: Type): Boolean = tp forallParts {
- case tp: NamedType => isNonLocal(tp.symbol)
- case _ => true
- }
- def noLeaksInClass(sym: ClassSymbol): Boolean =
- (sym.info.parents forall noLeaksIn) &&
- (sym.decls.toList forall (t => noLeaksIn(t.info)))
- check(noLeaksIn(tree.tpe))
- case If(cond, thenp, elsep) =>
- check(cond.isValue); check(thenp.isValue); check(elsep.isValue)
- check(cond.tpe.derivesFrom(defn.BooleanClass))
- case Match(selector, cases) =>
- check(selector.isValue)
- // are any checks that relate selector and patterns desirable?
- case CaseDef(pat, guard, body) =>
- check(pat.isValueOrPattern); check(guard.isValue); check(body.isValue)
- check(guard.tpe.derivesFrom(defn.BooleanClass))
- case Return(expr, from) =>
- check(expr.isValue); check(from.isTerm)
- check(from.tpe.termSymbol.isSourceMethod)
- case Try(block, handler, finalizer) =>
- check(block.isTerm)
- check(finalizer.isTerm)
- check(handler.isTerm)
- check(handler.tpe derivesFrom defn.FunctionClass(1))
- check(handler.tpe.baseType(defn.FunctionClass(1)).typeArgs.head <:< defn.ThrowableType)
- case Throw(expr) =>
- check(expr.isValue)
- check(expr.tpe.derivesFrom(defn.ThrowableClass))
- case SeqLiteral(elemtpt, elems) =>
- check(elemtpt.isValueType);
- for (elem <- elems) {
- check(elem.isValue)
- check(elem.tpe <:< elemtpt.tpe)
- }
- case TypeTree(original) =>
- if (!original.isEmpty) {
- check(original.isValueType)
- check(original.tpe == tree.tpe)
- }
- case SingletonTypeTree(ref) =>
- check(ref.isValue)
- check(ref.symbol.isStable)
- case SelectFromTypeTree(qualifier, name) =>
- check(qualifier.isValueType)
- check(qualifier.tpe =:= tree.tpe.normalizedPrefix)
- val denot = qualifier.tpe.member(name)
- check(denot.exists)
- check(denot.symbol == tree.symbol)
- case AndTypeTree(left, right) =>
- check(left.isValueType); check(right.isValueType)
- case OrTypeTree(left, right) =>
- check(left.isValueType); check(right.isValueType)
- case RefinedTypeTree(tpt, refinements) =>
- check(tpt.isValueType)
- def checkRefinements(forbidden: Set[Symbol], rs: List[tpd.Tree]): Unit = rs match {
- case r :: rs1 =>
- val rsym = r.symbol
- check(rsym.isTerm || rsym.isAbstractOrAliasType)
- if (rsym.isAbstractType) check(tpt.tpe.member(rsym.name).exists)
- check(rsym.info forallParts {
- case nt: NamedType => !(forbidden contains nt.symbol)
- case _ => true
- })
- checkRefinements(forbidden - rsym, rs1)
- case nil =>
- }
- checkRefinements(localSyms(refinements).toSet, refinements)
- case AppliedTypeTree(tpt, args) =>
- check(tpt.isValueType)
- val tparams = tpt.tpe.typeParams
- check(sameLength(tparams, args))
- (args, tparams map (_.info.bounds)).zipped foreach checkTypeArg
- case TypeBoundsTree(lo, hi) =>
- check(lo.isValueType); check(hi.isValueType)
- check(lo.tpe <:< hi.tpe)
- case Bind(sym, body) =>
- check(body.isValueOrPattern)
- check(!(tree.symbol is Method))
- body match {
- case Ident(nme.WILDCARD) =>
- case _ => check(body.tpe.widen =:= tree.symbol.info)
- }
- case Alternative(alts) =>
- for (alt <- alts) check(alt.isValueOrPattern)
- case UnApply(fun, args) =>
- check(fun.isTerm)
- for (arg <- args) check(arg.isValueOrPattern)
- val funtpe @ MethodType(_, _) = fun.tpe.widen
- fun.symbol.name match { // check arg arity
- case nme.unapplySeq =>
- // args need to be wrapped in (...: _*)
- check(args.length == 1)
- check(args.head.tpe.typeSymbol == defn.RepeatedParamClass)
- case nme.unapply =>
- val rtp = funtpe.resultType
- val rsym = rtp.dealias.typeSymbol
- if (rsym == defn.BooleanClass)
- check(args.isEmpty)
- else {
- check(rsym == defn.OptionClass)
- val normArgs = rtp.typeArgs match {
- case optionArg :: Nil =>
- optionArg.typeArgs match {
- case Nil =>
- optionArg :: Nil
- case tupleArgs if defn.TupleClasses contains optionArg.dealias.typeSymbol =>
- tupleArgs
- }
- case _ =>
- check(false)
- Nil
- }
- check(sameLength(normArgs, args))
- }
- }
- case ValDef(mods, name, tpt, rhs) =>
- check(!(tree.symbol is Method))
- if (!rhs.isEmpty) {
- check(rhs.isValue)
- check(rhs.tpe <:< tpt.tpe)
- }
- case DefDef(mods, name, tparams, vparamss, tpt, rhs) =>
- check(tree.symbol is Method)
- if (!rhs.isEmpty) {
- check(rhs.isValue)
- check(rhs.tpe <:< tpt.tpe)
- }
- case TypeDef(mods, name, _, tpt) =>
- check(tpt.tpe.isInstanceOf[TypeBounds])
- case Template(constr, parents, selfType, body) =>
- case ClassDef(mods, name, tparams, impl) =>
- case Import(expr, selectors) =>
- check(expr.isValue)
- check(expr.tpe.termSymbol.isStable)
- case PackageDef(pid, stats) =>
- check(pid.isTerm)
- check(pid.symbol is Package)
- case Annotated(annot, arg) =>
- check(annot.isInstantiation)
- check(annot.symbol.owner.isSubClass(defn.AnnotationClass))
- check(arg.isValueType || arg.isValue)
- case tpd.EmptyTree =>
- case SharedTree(shared) =>
- check(shared.isType || shared.isTerm)
- }
-
- implicit class TreeOps[ThisTree <: tpd.Tree](val tree: ThisTree) extends AnyVal {
-
- def isValue(implicit ctx: Context): Boolean =
- tree.isTerm && tree.tpe.widen.isValueType
-
- def isValueOrPattern(implicit ctx: Context) =
- tree.isValue || tree.isPattern
-
- def isValueType: Boolean =
- tree.isType && tree.tpe.isValueType
-
- def isInstantiation: Boolean = tree match {
- case Apply(Select(New(_), nme.CONSTRUCTOR), _) => true
- case _ => false
- }
-
- def checked(implicit ctx: Context): ThisTree = {
- if (ctx.settings.YcheckTypedTrees.value) checkType(tree)
- tree
- }
-
- def shallowFold[T](z: T)(op: (T, tpd.Tree) => T) =
- new ShallowFolder(op).apply(z, tree)
-
- def deepFold[T](z: T)(op: (T, tpd.Tree) => T) =
- new DeepFolder(op).apply(z, tree)
-
- def subst(from: List[Symbol], to: List[Symbol])(implicit ctx: Context): ThisTree =
- new TreeMapper(typeMap = new ctx.SubstSymMap(from, to)).apply(tree)
-
- def changeOwner(from: Symbol, to: Symbol)(implicit ctx: Context): ThisTree =
- new TreeMapper(ownerMap = (sym => if (sym == from) to else sym)).apply(tree)
- }
-
- class TreeMapper(val typeMap: TypeMap = IdentityTypeMap, val ownerMap: Symbol => Symbol = identity)(implicit ctx: Context) extends TreeTransformer[Type] {
- override def transform(tree: tpd.Tree): tpd.Tree = {
- val tree1 =
- if (tree.isEmpty) tree
- else tree.withType(typeMap(tree.tpe))
- val tree2 = tree1 match {
- case bind: tpd.Bind =>
- val sym = bind.symbol
- val newOwner = ownerMap(sym.owner)
- val newInfo = typeMap(sym.info)
- if ((newOwner ne sym.owner) || (newInfo ne sym.info))
- bind.withType(tpd.refType(sym.copy(owner = newOwner, info = newInfo)))
- else
- tree1
- case _ =>
- tree1
- }
- super.transform(tree2)
- }
- override def transform(trees: List[tpd.Tree]) = {
- val locals = localSyms(trees)
- val mapped = ctx.mapSymbols(locals, typeMap, ownerMap)
- if (locals eq mapped) super.transform(trees)
- else withSubstitution(locals, mapped).transform(trees)
- }
-
- def apply[ThisTree <: tpd.Tree](tree: ThisTree): ThisTree = transform(tree).asInstanceOf[ThisTree]
-
- def apply(annot: Annotation): Annotation = {
- val tree1 = apply(annot.tree)
- if (tree1 eq annot.tree) annot else ConcreteAnnotation(tree1)
- }
-
- /** The current tree map composed with a substitution [from -> to] */
- def withSubstitution(from: List[Symbol], to: List[Symbol]) =
- new TreeMapper(
- typeMap andThen ((tp: Type) => tp.substSym(from, to)),
- ownerMap andThen (from zip to).toMap)
- }
-
- // ensure that constructors are fully applied?
- // ensure that normal methods are fully applied?
-
- def localSyms(stats: List[tpd.Tree])(implicit ctx: Context): List[Symbol] =
- for (stat <- stats if (stat.isDef)) yield stat.symbol
-}
-
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala
index 395584a49..135437671 100644
--- a/src/dotty/tools/dotc/core/Types.scala
+++ b/src/dotty/tools/dotc/core/Types.scala
@@ -15,7 +15,7 @@ import SymDenotations._
import Decorators._
import Denotations._
import Periods._
-import TypedTrees.tpd._, TypedTrees.TreeMapper, printing.Texts._
+import ast.TypedTrees.tpd._, ast.TypedTrees.TreeMapper, printing.Texts._
import transform.Erasure
import printing.Printer
import scala.util.hashing.{ MurmurHash3 => hashing }
@@ -936,7 +936,7 @@ object Types {
lastDenotation
}
- private[core] final def withDenot(denot: Denotation): this.type = {
+ private[dotc] final def withDenot(denot: Denotation): this.type = {
lastDenotation = denot
this
}
diff --git a/src/dotty/tools/dotc/core/UntypedTrees.scala b/src/dotty/tools/dotc/core/UntypedTrees.scala
deleted file mode 100644
index f5ed04f11..000000000
--- a/src/dotty/tools/dotc/core/UntypedTrees.scala
+++ /dev/null
@@ -1,501 +0,0 @@
-package dotty.tools
-package dotc
-package core
-
-import util.Positions._, Types._, Contexts._, Constants._, Names._, NameOps._, Flags._
-import SymDenotations._, Symbols._, StdNames._, Annotations._, Trees._, TypedTrees._
-import TreeInfo._
-import Decorators._
-import language.higherKinds
-import collection.mutable.ListBuffer
-
-object UntypedTrees {
-
- object untpd extends Trees.Instance[Untyped] {
-
- // ----- Tree cases that exist in untyped form only ------------------
-
- /** A typed subtree of an untyped tree needs to be wrapped in a TypedSlice */
- case class TypedSplice(tree: TypedTree) extends UntypedTree
-
- /** mods object name impl */
- case class ModuleDef(mods: Modifiers, name: TermName, impl: Template)
- extends NameTree with ModDefTree {
- type ThisTree[T >: Untyped] <: Trees.NameTree[T] with Trees.ModDefTree[T] with ModuleDef
- }
-
- /** (vparams) => body */
- case class SymbolLit(str: String) extends Tree
- case class InterpolatedString(id: TermName, strings: List[Literal], elems: List[Tree]) extends Tree
- case class Function(args: List[Tree], body: Tree) extends Tree
- case class InfixOp(left: Tree, op: Name, right: Tree) extends Tree
- case class PostfixOp(tree: Tree, op: Name) extends Tree
- case class PrefixOp(op: Name, tree: Tree) extends Tree
- case class Parens(tree: Tree) extends Tree {
- def derivedParens(tree: Tree) = if (this.tree eq tree) this else Parens(tree).copyAttr(this)
- }
- case class Tuple(trees: List[Tree]) extends Tree {
- def derivedTuple(trees: List[Tree]) = if (this.trees eq trees) this else Tuple(trees).copyAttr(this)
- }
- case class WhileDo(cond: Tree, body: Tree) extends TermTree
- case class DoWhile(body: Tree, cond: Tree) extends TermTree
- case class ForYield(enums: List[Tree], expr: Tree) extends TermTree
- case class ForDo(enums: List[Tree], body: Tree) extends TermTree
- case class GenFrom(pat: Tree, expr: Tree) extends Tree
- case class GenAlias(pat: Tree, expr: Tree) extends Tree
- case class ContextBounds(bounds: TypeBoundsTree, cxBounds: List[Tree]) extends TypTree
- case class PatDef(mods: Modifiers, pats: List[Tree], tpt: Tree, rhs: Tree) extends Tree
-
- val unitLiteral = Literal(Constant())
- }
-
- import untpd._
-
- object Mode extends Enumeration {
- val Type, Expr, Pattern = Value
- }
-
- private type VarInfo = (NameTree, Tree)
-
- class UGen(implicit val ctx: Context) extends AnyVal {
-
- def scalaDot(name: Name): Select =
- Select(new TypedSplice(tpd.Ident(defn.ScalaPackageVal.termRef)), name)
-
- def scalaAnyRefConstr = scalaDot(tpnme.AnyRef)
- def scalaAnyValConstr = scalaDot(tpnme.AnyVal)
- def scalaAnyConstr = scalaDot(tpnme.Any)
- def scalaUnitConstr = scalaDot(tpnme.Unit)
- def productConstr = scalaDot(tpnme.Product)
- def productConstrN(n: Int) = scalaDot(("Product" + n).toTypeName)
- def serializableConstr = scalaDot(tpnme.Serializable)
-
- def constructor(mods: Modifiers, vparamss: List[List[ValDef]], rhs: Tree = EmptyTree()): DefDef =
- DefDef(mods, nme.CONSTRUCTOR, Nil, vparamss, TypeTree(), rhs)
-
- def selfDef(name: TermName, tpt: Tree) =
- ValDef(Modifiers(Private), name, tpt, EmptyTree())
-
- def makeTupleOrParens(ts: List[Tree]) = ts match {
- case t :: Nil => Parens(t)
- case _ => Tuple(ts)
- }
-
- def makeTuple(ts: List[Tree]) = ts match {
- case t :: Nil => t
- case _ => Tuple(ts)
- }
-
- def ref(tp: NamedType)(implicit ctx: Context): Tree =
- TypedSplice(tpd.ref(tp))
-
- /** new C(args) */
- def New(tpt: Tree, args: List[Tree]): Apply =
- Apply(Select(Trees.New(tpt), nme.CONSTRUCTOR), args)
-
- def syntheticParameter(pname: TermName): ValDef =
- ValDef(Modifiers(SyntheticTermParam), pname, TypeTree(), EmptyTree())
-
- private def labelDefAndCall(lname: TermName, rhs: Tree, call: Tree) = {
- val ldef = DefDef(Modifiers(Label), lname, Nil, ListOfNil, TypeTree(), rhs)
- Block(ldef, call)
- }
-
- private def derivedValDef(mods: Modifiers, named: NameTree, tpt: Tree, rhs: Tree) =
- ValDef(mods, named.name.asTermName, tpt , rhs).withPos(named.pos)
-
- /** Translate infix operation expression left op right
- */
- private def makeBinop(left: Tree, op: Name, right: Tree): Tree = {
- def assignToNamedArg(arg: Tree) = arg match {
- case Assign(Ident(name), rhs) => arg.derivedNamedArg(name, rhs)
- case _ => arg
- }
- if (isLeftAssoc(op)) {
- val args: List[Tree] = right match {
- case Parens(arg) => assignToNamedArg(arg) :: Nil
- case Tuple(args) => args mapConserve assignToNamedArg
- case _ => right :: Nil
- }
- Apply(Select(left, op.encode), args)
- } else {
- val x = ctx.freshName().toTermName
- Block(
- ValDef(Modifiers(Synthetic), x, TypeTree(), left),
- Apply(Select(right, op.encode), Ident(x)))
- }
- }
-
- /** Create tree for for-comprehension <for (enums) do body> or
- * <for (enums) yield body> where mapName and flatMapName are chosen
- * corresponding to whether this is a for-do or a for-yield.
- * The creation performs the following rewrite rules:
- *
- * 1.
- *
- * for (P <- G) E ==> G.foreach (P => E)
- *
- * Here and in the following (P => E) is interpreted as the function (P => E)
- * if P is a variable pattern and as the partial function { case P => E } otherwise.
- *
- * 2.
- *
- * for (P <- G) yield E ==> G.map (P => E)
- *
- * 3.
- *
- * for (P_1 <- G_1; P_2 <- G_2; ...) ...
- * ==>
- * G_1.flatMap (P_1 => for (P_2 <- G_2; ...) ...)
- *
- * 4.
- *
- * for (P <- G; E; ...) ...
- * =>
- * for (P <- G.filter (P => E); ...) ...
- *
- * 5. For any N:
- *
- * for (P_1 <- G; P_2 = E_2; val P_N = E_N; ...)
- * ==>
- * for (TupleN(P_1, P_2, ... P_N) <-
- * for (x_1 @ P_1 <- G) yield {
- * val x_2 @ P_2 = E_2
- * ...
- * val x_N & P_N = E_N
- * TupleN(x_1, ..., x_N)
- * } ...)
- *
- * If any of the P_i are variable patterns, the corresponding `x_i @ P_i' is not generated
- * and the variable constituting P_i is used instead of x_i
- *
- * @param mapName The name to be used for maps (either map or foreach)
- * @param flatMapName The name to be used for flatMaps (either flatMap or foreach)
- * @param enums The enumerators in the for expression
- * @param body The body of the for expression
- */
- private def makeFor(mapName: TermName, flatMapName: TermName, enums: List[Tree], body: Tree): Tree = {
-
- /** Make a function value pat => body.
- * If pat is a var pattern id: T then this gives (id: T) => body
- * Otherwise this gives { case pat => body }
- */
- def makeLambda(pat: Tree, body: Tree): Tree = pat match {
- case VarPattern(named, tpt) =>
- Function(derivedValDef(Modifiers(Param), named, tpt, EmptyTree()) :: Nil, body)
- case _ =>
- Match(EmptyTree(), CaseDef(pat, EmptyTree(), body) :: Nil)
- }
-
- /** If `pat` is not yet a `Bind` wrap it in one with a fresh name
- */
- def makeBind(pat: Tree): Tree = pat match {
- case Bind(_, _) => pat
- case _ => Bind(ctx.freshName().toTermName, pat)
- }
-
- /** Is pattern `pat` irrefutable when matched against `rhs`?
- * We only can do a simple syntactic check here; a more refined check
- * is done later prompted by the presence of a "withFilterIfRefutable" call.
- */
- def isIrrefutable(pat: Tree, rhs: Tree): Boolean = {
- def matchesTuple(pats: List[Tree], rhs: Tree): Boolean = rhs match {
- case Tuple(trees) => (pats corresponds trees)(isIrrefutable)
- case Parens(rhs1) => matchesTuple(pats, rhs1)
- case Block(_, rhs1) => matchesTuple(pats, rhs1)
- case If(_, thenp, elsep) => matchesTuple(pats, thenp) && matchesTuple(pats, elsep)
- case Match(_, cases) => cases forall (matchesTuple(pats, _))
- case CaseDef(_, _, rhs1) => matchesTuple(pats, rhs)
- case Throw(_) => true
- case _ => false
- }
- pat match {
- case Bind(_, pat1) => isIrrefutable(pat1, rhs)
- case Parens(pat1) => isIrrefutable(pat1, rhs)
- case Tuple(pats) => matchesTuple(pats, rhs)
- case _ => isVarPattern(pat)
- }
- }
-
- /** Make a pattern filter:
- * rhs.withFilterIfRefutable { case pat => true case _ => false }
- */
- def makePatFilter(rhs: Tree, pat: Tree): Tree = {
- val cases = List(
- CaseDef(pat, EmptyTree(), Literal(Constant(true))),
- CaseDef(Ident(nme.WILDCARD), EmptyTree(), Literal(Constant(false)))
- )
- Apply(Select(rhs, nme.withFilterIfRefutable), Match(EmptyTree(), cases))
- }
-
- /** rhs.name with a pattern filter on rhs unless `pat` is irrefutable when
- * matched against `rhs`.
- */
- def rhsSelect(rhs: Tree, name: TermName, pat: Tree) = {
- val rhs1 = if (isIrrefutable(pat, rhs)) rhs else makePatFilter(rhs, pat)
- Select(rhs1, name)
- }
-
- enums match {
- case (enum @ GenFrom(pat, rhs)) :: Nil =>
- Apply(rhsSelect(rhs, mapName, pat), makeLambda(pat, body))
- case GenFrom(pat, rhs) :: (rest @ (GenFrom(_, _) :: _)) =>
- val cont = makeFor(mapName, flatMapName, rest, body)
- Apply(rhsSelect(rhs, flatMapName, pat), makeLambda(pat, cont))
- case (enum @ GenFrom(pat, rhs)) :: (rest @ GenAlias(_, _) :: _) =>
- val (valeqs, rest1) = rest.span(_.isInstanceOf[GenAlias])
- val pats = valeqs map { case GenAlias(pat, _) => pat }
- val rhss = valeqs map { case GenAlias(_, rhs) => rhs }
- val defpat1 = makeBind(pat)
- val defpats = pats map makeBind
- val pdefs = (defpats, rhss).zipped map (makePatDef(Modifiers(), _, _))
- val ids = (defpat1 :: defpats) map { case Bind(name, _) => Ident(name) }
- val rhs1 = makeFor(nme.map, nme.flatMap, GenFrom(defpat1, rhs) :: Nil, Block(pdefs, makeTuple(ids)))
- val allpats = pat :: pats
- val vfrom1 = GenFrom(makeTuple(allpats), rhs1)
- makeFor(mapName, flatMapName, vfrom1 :: rest1, body)
- case (enum @ GenFrom(pat, rhs)) :: test :: rest =>
- val filtered = Apply(rhsSelect(rhs, nme.withFilter, pat), makeLambda(pat, test))
- makeFor(mapName, flatMapName, GenFrom(pat, filtered) :: rest, body)
- case _ =>
- EmptyTree() //may happen for erroneous input
- }
- }
-
- private def makeAnnotated(cls: Symbol, tree: Tree) =
- Annotated(TypedSplice(tpd.New(cls.typeConstructor)), tree)
-
- /** Returns list of all pattern variables, possibly with their types,
- * without duplicates
- */
- private def getVariables(tree: Tree): List[VarInfo] =
- getVars(new ListBuffer[VarInfo], tree).toList
-
- /** In case there is exactly one variable x_1 in pattern
- * val/var p = e ==> val/var x_1 = (e: @unchecked) match (case p => (x_1))
- *
- * in case there are zero or more than one variables in pattern
- * val/var p = e ==> private synthetic val t$ = (e: @unchecked) match (case p => (x_1, ..., x_N))
- * val/var x_1 = t$._1
- * ...
- * val/var x_N = t$._N
- * If the original pattern variable carries a type annotation, so does the corresponding
- * ValDef.
- */
- private def makePatDef(mods: Modifiers, pat: Tree, rhs: Tree): Tree = pat match {
- case VarPattern(named, tpt) =>
- derivedValDef(mods, named, tpt, rhs)
- case _ =>
- val rhsUnchecked = makeAnnotated(defn.UncheckedAnnot, rhs)
- val vars = getVariables(pat)
- val ids = for ((named, _) <- vars) yield Ident(named.name)
- val caseDef = CaseDef(pat, EmptyTree(), makeTuple(ids))
- val matchExpr = Match(rhsUnchecked, caseDef :: Nil)
- vars match {
- case (named, tpt) :: Nil =>
- derivedValDef(mods, named, tpt, matchExpr)
- case _ =>
- val tmpName = ctx.freshName().toTermName
- val patMods = Modifiers(PrivateLocal | Synthetic | (mods.flags & Lazy))
- val firstDef = ValDef(patMods, tmpName, TypeTree(), matchExpr)
- def selector(n: Int) = Select(Ident(tmpName), ("_" + n).toTermName)
- val restDefs =
- for (((named, tpt), n) <- vars.zipWithIndex)
- yield derivedValDef(mods, named, tpt, selector(n))
- TempTrees(firstDef :: restDefs)
- }
- }
-
- def desugarContextBounds(tparams: List[TypeDef], vparamss: List[List[ValDef]], ofClass: Boolean): (List[TypeDef], List[List[ValDef]]) = {
- val epbuf = new ListBuffer[ValDef]
- def makeEvidenceParam(cxBound: Tree): ValDef = ???
- val tparams1 = tparams map {
- case tparam @ TypeDef(mods, name, ttparams, ContextBounds(tbounds, cxbounds)) =>
- for (cxbound <- cxbounds) {
- val accessMods = if (ofClass) PrivateOrLocal else EmptyFlags
- val epname = (nme.EVIDENCE_PARAM_PREFIX.toString + epbuf.length).toTermName
- epbuf +=
- ValDef(Modifiers(Implicit | Param | accessMods), epname, cxbound, EmptyTree())
- }
- tparam.derivedTypeDef(mods, name, ttparams, tbounds)
- case tparam =>
- tparam
- }
- val evidenceParams = epbuf.toList
- val vparamss1 = vparamss.reverse match {
- case (vparams @ (vparam :: _)) :: rvparamss if vparam.mods is Implicit =>
- ((vparams ++ evidenceParams) :: rvparamss).reverse
- case _ =>
- vparamss :+ evidenceParams
- }
- (tparams1, vparamss1)
- }
-
- def desugarContextBounds(tree: Tree): Tree = tree match {
- case DefDef(mods, name, tparams, vparamss, tpt, rhs) =>
- val (tparams1, vparamss1) =
- desugarContextBounds(tparams, vparamss, ofClass = false)
- tree.derivedDefDef(mods, name, tparams1, vparamss, tpt, rhs)
- case ClassDef(
- mods, name, tparams, templ @ Template(constr, parents, self, body)) =>
- val (tparams1, vparamss1) =
- desugarContextBounds(tparams, constr.vparamss, ofClass = true)
- val constr1 = constr.derivedDefDef(
- constr.mods, constr.name, constr.tparams, vparamss1, constr.tpt, constr.rhs)
- val templ1 = templ.derivedTemplate(constr1, parents, self, body)
- tree.derivedClassDef(mods, name, tparams1, templ1)
- case _ => tree
- }
-
- def desugarAnonClass(templ: Template): Tree = {
- val x = tpnme.ANON_CLASS
- val clsDef = ClassDef(Modifiers(Final), x, Nil, templ)
- Block(clsDef, New(Ident(x), Nil))
- }
-
- def desugar(tree: Tree, mode: Mode.Value): Tree = {
- def isPatternVar(id: Ident) =
- mode == Mode.Pattern && isVarPattern(id) && id.name != nme.WILDCARD
- tree match { // todo: move general tree desugaring to typer, and keep only untyped trees here?
- case id @ Ident(_) if isPatternVar(id) =>
- Bind(id.name, Ident(nme.WILDCARD))
- case Typed(id @ Ident(_), tpt) if isPatternVar(id) =>
- Bind(id.name, Typed(Ident(nme.WILDCARD), tpt)).withPos(id.pos)
- case New(templ: Template) =>
- desugarAnonClass(templ)
- case Assign(Apply(fn, args), rhs) =>
- Apply(Select(fn, nme.update), args :+ rhs)
- case If(cond, thenp, EmptyTree()) =>
- If(cond, thenp, unitLiteral)
- case _: DefDef| _: ClassDef =>
- desugarContextBounds(tree)
- case ModuleDef(mods, name, tmpl @ Template(constr, parents, self, body)) =>
- // <module> val name: name$ = New(name$)
- // <module> final class name$ extends parents { self: name.type => body }
- val clsName = name.moduleClassName
- val clsRef = Ident(clsName)
- val modul = ValDef(mods | ModuleCreationFlags, name, clsRef, clsRef)
- val clsSelf = self.derivedValDef(self.mods, self.name, SingletonTypeTree(Ident(name)), self.rhs)
- val clsTmpl = tmpl.derivedTemplate(constr, parents, clsSelf, body)
- val cls = ClassDef(mods & AccessFlags | ModuleClassCreationFlags, clsName, Nil, clsTmpl)
- TempTrees(List(modul, cls))
- case SymbolLit(str) =>
- New(ref(defn.SymbolClass.typeConstructor), Literal(Constant(str)) :: Nil)
- case InterpolatedString(id, strs, elems) =>
- Apply(Select(Apply(Ident(nme.StringContext), strs), id), elems)
- case Function(args, body) =>
- if (mode == Mode.Type) // FunctionN[args: _*, body]
- AppliedTypeTree(
- ref(defn.FunctionClass(args.length).typeConstructor),
- args :+ body)
- else { // { def $anonfun(args) = body; $anonfun }
- val params = args.asInstanceOf[List[ValDef]]
- Block(
- DefDef(Modifiers(Synthetic), nme.ANON_FUN, Nil, params :: Nil, EmptyTree(), body),
- Ident(nme.ANON_FUN)
- )
- }
- case InfixOp(l, op, r) =>
- mode match {
- case Mode.Expr => // l.op'(r), or val x = r; l.op;(x), plus handle named args specially
- makeBinop(l, op, r)
- case Mode.Pattern => // op'(l, r)
- Apply(Ident(op.encode), l :: r :: Nil)
- case Mode.Type => // op'[l, r]
- AppliedTypeTree(Ident(op.encode), l :: r :: Nil)
- }
- case PostfixOp(t, op) =>
- if (mode == Mode.Type && op == nme.raw.STAR)
- AppliedTypeTree(ref(defn.RepeatedParamType), t)
- else {
- assert(mode == Mode.Expr)
- if (op == nme.WILDCARD) tree // desugar later by eta expansion
- else Select(t, op.encode)
- }
- case PrefixOp(op, t) =>
- if (mode == Mode.Type && op == nme.ARROWkw)
- AppliedTypeTree(ref(defn.ByNameParamClass.typeConstructor), t)
- else
- Select(t, nme.UNARY_PREFIX ++ op.encode)
- case Parens(t) =>
- t
- case Tuple(ts) =>
- def PairTypeTree(l: Tree, r: Tree) =
- AppliedTypeTree(ref(defn.PairClass.typeConstructor), l :: r :: Nil)
- if (mode == Mode.Type) ts.reduceRight(PairTypeTree)
- else if (ts.isEmpty) unitLiteral
- else ts.reduceRight(Pair(_, _))
- case WhileDo(cond, body) =>
- // { <label> def while$(): Unit = if (cond) { body; while$() } ; while$() }
- val call = Apply(Ident(nme.WHILE_PREFIX), Nil)
- val rhs = If(cond, Block(body, call), unitLiteral)
- labelDefAndCall(nme.WHILE_PREFIX, rhs, call)
- case DoWhile(body, cond) =>
- // { label def doWhile$(): Unit = { body; if (cond) doWhile$() } ; doWhile$() }
- val call = Apply(Ident(nme.DO_WHILE_PREFIX), Nil)
- val rhs = Block(body, If(cond, call, unitLiteral))
- labelDefAndCall(nme.DO_WHILE_PREFIX, rhs, call)
- case ForDo(enums, body) =>
- makeFor(nme.foreach, nme.foreach, enums, body) orElse tree
- case ForYield(enums, body) =>
- makeFor(nme.map, nme.flatMap, enums, body) orElse tree
- case PatDef(mods, pats, tpt, rhs) =>
- val pats1 = if (tpt.isEmpty) pats else pats map (Typed(_, tpt))
- combine(pats1 map (makePatDef(mods, _, rhs)))
- case _ =>
- tree
- }
- }.withPos(tree.pos)
- }
-
- def ugen(implicit ctx: Context) = new UGen
-
- /** If tree is a variable pattern, return its name and type, otherwise return None.
- */
- private object VarPattern {
- def unapply(tree: Tree): Option[VarInfo] = tree match {
- case id: Ident => Some(id, TypeTree())
- case Typed(id: Ident, tpt) => Some((id, tpt))
- case _ => None
- }
- }
-
- /** Traverse pattern and collect all variable names with their types in buffer.
- * Works for expanded as well as unexpanded patterns
- *
- */
- private object getVars extends TreeAccumulator[ListBuffer[VarInfo]] {
- override def apply(buf: ListBuffer[VarInfo], tree: Tree): ListBuffer[VarInfo] = {
- def seenName(name: Name) = buf exists (_._1.name == name)
- def add(named: NameTree, t: Tree): ListBuffer[VarInfo] =
- if (seenName(named.name)) buf else buf += ((named, t))
- tree match {
- case Bind(nme.WILDCARD, _) =>
- foldOver(buf, tree)
- case tree @ Bind(_, Typed(tree1, tpt)) if !mayBeTypePat(tpt) =>
- apply(add(tree, tpt), tree1)
- case tree @ Bind(_, tree1) =>
- apply(add(tree, TypeTree()), tree1)
- case Typed(id: Ident, t) if isVarPattern(id) =>
- add(id, t)
- case id: Ident if isVarPattern(id) =>
- add(id, TypeTree())
- case _ =>
- foldOver(buf, tree)
- }
- }
- }
-
- implicit class UntypedTreeDecorator(val self: Tree) extends AnyVal {
- def locateEnclosing(base: List[Tree], pos: Position): List[Tree] = {
- def encloses(elem: Any) = elem match {
- case t: Tree => t.envelope contains pos
- case _ => false
- }
- base.productIterator find encloses match {
- case Some(tree: Tree) => locateEnclosing(tree :: base, pos)
- case none => base
- }
- }
- }
-} \ No newline at end of file
diff --git a/src/dotty/tools/dotc/core/pickling/ClassfileParser.scala b/src/dotty/tools/dotc/core/pickling/ClassfileParser.scala
index 02ee9d9cc..9586b9436 100644
--- a/src/dotty/tools/dotc/core/pickling/ClassfileParser.scala
+++ b/src/dotty/tools/dotc/core/pickling/ClassfileParser.scala
@@ -5,7 +5,7 @@ package pickling
import Contexts._, Symbols._, Types._, Names._, StdNames._, NameOps._, Scopes._, Decorators._
import SymDenotations._, UnPickler._, Constants._, Annotations._, util.Positions._
-import TypedTrees.tpd._
+import ast.TypedTrees.tpd._
import java.io.{ File, IOException }
import java.lang.Integer.toHexString
import scala.collection.{ mutable, immutable }
diff --git a/src/dotty/tools/dotc/core/pickling/UnPickler.scala b/src/dotty/tools/dotc/core/pickling/UnPickler.scala
index 5083ccf52..42899ef44 100644
--- a/src/dotty/tools/dotc/core/pickling/UnPickler.scala
+++ b/src/dotty/tools/dotc/core/pickling/UnPickler.scala
@@ -9,7 +9,8 @@ import java.lang.Double.longBitsToDouble
import Contexts._, Symbols._, Types._, Scopes._, SymDenotations._, Names._, NameOps._
import StdNames._, Denotations._, NameOps._, Flags._, Constants._, Annotations._
-import util.Positions._, TypedTrees.tpd._, TypedTrees.TreeOps
+import util.Positions._
+import ast.Trees, ast.TypedTrees.tpd._, ast.TypedTrees.TreeOps
import printing.Texts._
import printing.Printer
import io.AbstractFile