diff options
author | Paul Phillips <paulp@improving.org> | 2012-03-19 15:07:57 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2012-03-19 15:44:39 -0700 |
commit | 50bf852c9a48312e60b441d052150fdd78b52a1a (patch) | |
tree | 9447a262361a8a9642d2bb69f1ffbc2efa9bc0ac /src/library | |
parent | 78c15103d54e58b0ecd193b90e2d56b967967d6c (diff) | |
download | scala-50bf852c9a48312e60b441d052150fdd78b52a1a.tar.gz scala-50bf852c9a48312e60b441d052150fdd78b52a1a.tar.bz2 scala-50bf852c9a48312e60b441d052150fdd78b52a1a.zip |
Tree adjustments.
I noticed that if we gave Ident a "qualifier" method which is
always EmptyTree, a whole bunch of code could be simplified.
A transparent subclass of Apply which preserves the source
level "new" a little longer than never.
Since productPrefix is tied up in reification - and oh I
detest this "String"-based programming, we shouldn't have to
wait until everyone learns this independently to change it -
I added "printingPrefix" to Tree, which defaults to
productPrefix but can be changed without breaking reify.
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/scala/reflect/api/TreePrinters.scala | 2 | ||||
-rw-r--r-- | src/library/scala/reflect/api/Trees.scala | 25 |
2 files changed, 19 insertions, 8 deletions
diff --git a/src/library/scala/reflect/api/TreePrinters.scala b/src/library/scala/reflect/api/TreePrinters.scala index 21b55e9c0e..43865915d3 100644 --- a/src/library/scala/reflect/api/TreePrinters.scala +++ b/src/library/scala/reflect/api/TreePrinters.scala @@ -41,7 +41,7 @@ trait TreePrinters { self: Universe => else if (tree.original != null) print(".setOriginal(", tree.original, ")") case tree: Tree => - print(tree.productPrefix+"(") + print(tree.printingPrefix+"(") val it = tree.productIterator while (it.hasNext) { it.next() match { diff --git a/src/library/scala/reflect/api/Trees.scala b/src/library/scala/reflect/api/Trees.scala index a355207ff0..a8276dc853 100644 --- a/src/library/scala/reflect/api/Trees.scala +++ b/src/library/scala/reflect/api/Trees.scala @@ -76,6 +76,12 @@ trait Trees { self: Universe => private[this] var rawpos: Position = NoPosition + /** Prefix under which to print this tree type. Defaults to product + * prefix (e.g. DefTree) but because that is used in reification + * it cannot be altered without breaking reflection. + */ + def printingPrefix = productPrefix + def pos = rawpos def pos_=(pos: Position) = rawpos = pos def setPos(pos: Position): this.type = { rawpos = pos; this } @@ -249,6 +255,7 @@ trait Trees { self: Universe => * are in DefTrees. */ trait RefTree extends SymTree { + def qualifier: Tree // empty for Idents def name: Name } @@ -489,16 +496,14 @@ trait Trees { self: Universe => /** Factory method for object creation `new tpt(args_1)...(args_n)` * A `New(t, as)` is expanded to: `(new t).<init>(as)` */ - def New(tpt: Tree, argss: List[List[Tree]]): Tree = { - // todo. we need to expose names in scala.reflect.api - val superRef: Tree = Select(New(tpt), nme.CONSTRUCTOR) - if (argss.isEmpty) Apply(superRef, Nil) - else (superRef /: argss) (Apply) + def New(tpt: Tree, argss: List[List[Tree]]): Tree = argss match { + case Nil => new ApplyConstructor(tpt, Nil) + case xs :: rest => rest.foldLeft(new ApplyConstructor(tpt, xs): Tree)(Apply) } /** 0-1 argument list new, based on a type. */ def New(tpe: Type, args: Tree*): Tree = - New(TypeTree(tpe), List(args.toList)) + new ApplyConstructor(TypeTree(tpe), args.toList) /** Type annotation, eliminated by explicit outer */ case class Typed(expr: Tree, tpt: Tree) @@ -537,6 +542,10 @@ trait Trees { self: Universe => class ApplyImplicitView(fun: Tree, args: List[Tree]) extends Apply(fun, args) + class ApplyConstructor(tpt: Tree, args: List[Tree]) extends Apply(Select(New(tpt), nme.CONSTRUCTOR), args) { + override def printingPrefix = "ApplyConstructor" + } + /** Dynamic value application. * In a dynamic application q.f(as) * - q is stored in qual @@ -575,7 +584,9 @@ trait Trees { self: Universe => Select(qualifier, sym.name) setSymbol sym /** Identifier <name> */ - case class Ident(name: Name) extends RefTree + case class Ident(name: Name) extends RefTree { + def qualifier: Tree = EmptyTree + } def Ident(name: String): Ident = Ident(newTermName(name)) |