aboutsummaryrefslogtreecommitdiff
path: root/src/dotty
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2013-05-22 19:22:28 +0200
committerMartin Odersky <odersky@gmail.com>2013-05-22 19:22:28 +0200
commit66fe5aaba6d5f7ae3694bcc942487cd1fe00c533 (patch)
tree87466b4ab10613bb2c174f01c6185fd268a3cd35 /src/dotty
parent965a62d4a165da7e5a53c9afdba3175e10fe714b (diff)
downloaddotty-66fe5aaba6d5f7ae3694bcc942487cd1fe00c533.tar.gz
dotty-66fe5aaba6d5f7ae3694bcc942487cd1fe00c533.tar.bz2
dotty-66fe5aaba6d5f7ae3694bcc942487cd1fe00c533.zip
Eliminating Trees.TypedTree and Trees.UntypedTree
Replaced by tpd.Tree and untpd.Tree. Also some cleanups in RefinedPrinters.
Diffstat (limited to 'src/dotty')
-rw-r--r--src/dotty/tools/dotc/ast/Trees.scala6
-rw-r--r--src/dotty/tools/dotc/ast/TypedTrees.scala2
-rw-r--r--src/dotty/tools/dotc/ast/UntypedTrees.scala2
-rw-r--r--src/dotty/tools/dotc/printing/RefinedPrinter.scala53
4 files changed, 32 insertions, 31 deletions
diff --git a/src/dotty/tools/dotc/ast/Trees.scala b/src/dotty/tools/dotc/ast/Trees.scala
index 9f8c2ca93..dd4567c50 100644
--- a/src/dotty/tools/dotc/ast/Trees.scala
+++ b/src/dotty/tools/dotc/ast/Trees.scala
@@ -21,8 +21,6 @@ object Trees {
// 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
@@ -558,7 +556,7 @@ object Trees {
* 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])
+ case class Import[T >: Untyped](expr: Tree[T], selectors: List[Tree[Untyped]])
extends DenotingTree[T] {
type ThisTree[T >: Untyped] = Import[T]
}
@@ -862,7 +860,7 @@ object Trees {
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 {
+ def derivedImport(expr: Tree[T], selectors: List[Tree[Untyped]]): Import[T] = tree match {
case tree: Import[_] if (expr eq tree.expr) && (selectors eq tree.selectors) => tree
case _ => Import(expr, selectors).copyAttr(tree)
}
diff --git a/src/dotty/tools/dotc/ast/TypedTrees.scala b/src/dotty/tools/dotc/ast/TypedTrees.scala
index 958927148..266664cce 100644
--- a/src/dotty/tools/dotc/ast/TypedTrees.scala
+++ b/src/dotty/tools/dotc/ast/TypedTrees.scala
@@ -211,7 +211,7 @@ object tpd extends Trees.Instance[Type] {
.withType(refType(cls)).checked
}
- def Import(expr: Tree, selectors: List[Trees.UntypedTree])(implicit ctx: Context): Import =
+ def Import(expr: Tree, selectors: List[untpd.Tree])(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 =
diff --git a/src/dotty/tools/dotc/ast/UntypedTrees.scala b/src/dotty/tools/dotc/ast/UntypedTrees.scala
index 16a1efa03..f733734a7 100644
--- a/src/dotty/tools/dotc/ast/UntypedTrees.scala
+++ b/src/dotty/tools/dotc/ast/UntypedTrees.scala
@@ -15,7 +15,7 @@ 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
+ case class TypedSplice(tree: tpd.Tree) extends Tree
/** mods object name impl */
case class ModuleDef(mods: Modifiers, name: TermName, impl: Template)
diff --git a/src/dotty/tools/dotc/printing/RefinedPrinter.scala b/src/dotty/tools/dotc/printing/RefinedPrinter.scala
index bcf58e4e5..c4ee76d3a 100644
--- a/src/dotty/tools/dotc/printing/RefinedPrinter.scala
+++ b/src/dotty/tools/dotc/printing/RefinedPrinter.scala
@@ -10,6 +10,7 @@ import ast.untpd
import scala.annotation.switch
class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
+
override protected def recursionLimitExceeeded() = {}
/** The closest enclosing DefDef, TypeDef, or ClassDef node */
@@ -91,13 +92,13 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
def tparamsText(params: List[Tree[T]]): Text =
"[" ~ toText(params, ", ") ~ "]" provided params.nonEmpty
- def addVparamssText[T >: Untyped](txt: Text, vparamss: List[List[ValDef[T]]]): Text =
+ def addVparamssText(txt: Text, vparamss: List[List[ValDef[T]]]): Text =
(txt /: vparamss)((txt, vparams) => txt ~ "(" ~ toText(vparams, ", ") ~ ")")
- def blockText[T >: Untyped](trees: List[Tree[T]]): Text =
+ def blockText(trees: List[Tree[T]]): Text =
"{" ~ toText(trees, "\n") ~ "}"
- def caseBlockText[T >: Untyped](tree: Tree[T]): Text = tree match {
+ def caseBlockText(tree: Tree[T]): Text = tree match {
case Block(stats, expr) => toText(stats :+ expr, "\n")
case expr => toText(expr)
}
@@ -110,6 +111,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
case untpd.Function(_, tpt) => " <% " ~ toText(tpt)
}
+ import untpd._
+
val txt: Text = tree match {
case id: BackquotedIdent[_] =>
"`" ~ toText(id.name) ~ "`"
@@ -141,7 +144,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
blockText(stats :+ expr)
case If(cond, thenp, elsep) =>
changePrec(GlobalPrec) {
- "if " ~ toText(cond) ~ (" then" provided !cond.isInstanceOf[untpd.Parens]) ~~ toText(thenp) ~ optText(elsep)(" else " ~ _)
+ "if " ~ toText(cond) ~ (" then" provided !cond.isInstanceOf[Parens]) ~~ toText(thenp) ~ optText(elsep)(" else " ~ _)
}
case Match(sel, cases) =>
if (sel.isEmpty) blockText(cases)
@@ -224,7 +227,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
toText(name) ~ tparamsText(tparams) ~ toText(impl)
}
case Import(expr, selectors) =>
- def selectorText(sel: UntypedTree): Text = sel match {
+ def selectorText(sel: Tree): Text = sel match {
case Pair(l, r) => toTextGlobal(l) ~ " => " ~ toTextGlobal(r)
case _ => toTextGlobal(sel)
}
@@ -235,7 +238,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
"import " ~ toTextLocal(expr) ~ "." ~ selectorsText
case PackageDef(pid, stats) =>
val statsText = stats match {
- case (pdef: PackageDef[_]) :: Nil => toText(pdef)
+ case (pdef: PackageDef) :: Nil => toText(pdef)
case _ => toTextGlobal(stats, "\n")
}
val bodyText =
@@ -247,13 +250,13 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
"<empty>"
case SharedTree(shared) =>
toText(shared)
- case untpd.TypedSplice(t) =>
+ case TypedSplice(t) =>
toText(t)
- case untpd.ModuleDef(mods, name, impl) =>
+ case ModuleDef(mods, name, impl) =>
toText(mods, "object") ~~ toText(name) ~ " extends " ~ toText(impl)
- case untpd.SymbolLit(str) =>
+ case SymbolLit(str) =>
"'" + str
- case untpd.InterpolatedString(id, strings, elems) =>
+ case InterpolatedString(id, strings, elems) =>
def interleave(strs: List[Text], elems: List[Text]): Text = ((strs, elems): @unchecked) match {
case (Nil, Nil) => ""
case (str :: Nil, Nil) => str
@@ -262,9 +265,9 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
val strTexts = strings map (str => Str(escapedString(str.const.stringValue)))
val elemsTexts = elems map (elem => "{" ~ toTextGlobal(elem) ~ "}")
toText(id) ~ "\"" ~ interleave(strTexts, elemsTexts) ~ "\""
- case untpd.Function(args, body) =>
+ case Function(args, body) =>
var implicitSeen: Boolean = false
- def argToText(arg: untpd.Tree) = arg match {
+ def argToText(arg: Tree) = arg match {
case ValDef(mods, name, tpt, _) =>
val implicitText =
if ((mods is Implicit) && !implicitSeen) { implicitSeen = true; "implicit " }
@@ -280,34 +283,34 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
changePrec(GlobalPrec) {
argsText ~ " => " ~ toText(body)
}
- case untpd.InfixOp(l, op, r) =>
+ case InfixOp(l, op, r) =>
val opPrec = parsing.precedence(op)
changePrec(opPrec) { toText(l) ~ " " ~ toText(op) ~ " " ~ toText(r) }
- case untpd.PostfixOp(l, op) =>
+ case PostfixOp(l, op) =>
changePrec(InfixPrec) { toText(l) ~ " " ~ toText(op) }
- case untpd.PrefixOp(op, r) =>
+ case PrefixOp(op, r) =>
changePrec(DotPrec) { toText(op) ~ " " ~ toText(r) }
- case untpd.Parens(t) =>
+ case Parens(t) =>
"(" ~ toTextGlobal(t) ~ ")"
- case untpd.Tuple(ts) =>
+ case Tuple(ts) =>
"(" ~ toTextGlobal(ts, ", ") ~ ")"
- case untpd.WhileDo(cond, body) =>
+ case WhileDo(cond, body) =>
changePrec(GlobalPrec) { "while " ~ toText(cond) ~ " do " ~ toText(body) }
- case untpd.DoWhile(cond, body) =>
+ case DoWhile(cond, body) =>
changePrec(GlobalPrec) { "do " ~ toText(body) ~ " while " ~ toText(cond) }
- case untpd.ForYield(enums, expr) =>
+ case ForYield(enums, expr) =>
forText(enums, expr, " yield ")
- case untpd.ForDo(enums, expr) =>
+ case ForDo(enums, expr) =>
forText(enums, expr, " do ")
- case untpd.GenFrom(pat, expr) =>
+ case GenFrom(pat, expr) =>
toText(pat) ~ " <- " ~ toText(expr)
- case untpd.GenAlias(pat, expr) =>
+ case GenAlias(pat, expr) =>
toText(pat) ~ " = " ~ toText(expr)
- case untpd.ContextBounds(bounds, cxBounds) =>
+ case ContextBounds(bounds, cxBounds) =>
(toText(bounds) /: cxBounds) {(t, cxb) =>
t ~ cxBoundToText(cxb)
}
- case untpd.PatDef(mods, pats, tpt, rhs) =>
+ case PatDef(mods, pats, tpt, rhs) =>
toText(mods, "val") ~~ toText(pats, ", ") ~ optText(tpt)(": " ~ _) ~
optText(rhs)(" = " ~ _)
case _ =>