diff options
author | Paul Phillips <paulp@improving.org> | 2012-05-03 10:10:39 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2012-05-03 10:53:03 -0700 |
commit | 0cb886ae44505334dd5e8408b9355a53bc00e578 (patch) | |
tree | 41e66ce4b4265cf4a53e5774236d9248afcdf5dd /src/library/scala/reflect/api/Trees.scala | |
parent | ca74659bb06611b87474ffe2fd17b131cd3d34b0 (diff) | |
download | scala-0cb886ae44505334dd5e8408b9355a53bc00e578.tar.gz scala-0cb886ae44505334dd5e8408b9355a53bc00e578.tar.bz2 scala-0cb886ae44505334dd5e8408b9355a53bc00e578.zip |
Removed BackquotedIdent.
In favor of a marker attachment using Attachment, as suggested in
comments. (The Attachment interface needs work.) I did this bit trying
to fix SI-5715, but it's still a bit elusive because the Ident node is
thrown away as soon as there's a member definition.
Also, as far as I can see this will if anything propagate the
backquotedness of an identifier less effectively than before, because
TreeCopiers don't copy attachments. Maybe that's on the "todo" list? The
whole idea seems to depend on their being propagated to copies.
Diffstat (limited to 'src/library/scala/reflect/api/Trees.scala')
-rw-r--r-- | src/library/scala/reflect/api/Trees.scala | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/src/library/scala/reflect/api/Trees.scala b/src/library/scala/reflect/api/Trees.scala index b82972c9bc..ca4e60f3f6 100644 --- a/src/library/scala/reflect/api/Trees.scala +++ b/src/library/scala/reflect/api/Trees.scala @@ -16,6 +16,9 @@ trait Trees { self: Universe => type Modifiers >: Null <: AbsModifiers val NoMods: Modifiers + // TODO - Where do I put this? + object BackquotedIdentifier + abstract class AbsModifiers { def modifiers: Set[Modifier] def hasModifier(mod: Modifier): Boolean @@ -96,6 +99,20 @@ trait Trees { self: Universe => case _ => rawatt = NontrivialAttachment(pos, collection.mutable.ListBuffer[Any](att)) } + + // a) why didn't this method already exist + // b) what is all this "Any" business? + // c) am I reverse-engineering this correctly? It shouldn't be hard + // to figure out what is attached. + def attachments: List[Any] = rawatt match { + case NoPosition => Nil + case NontrivialAttachment(pos, atts) => pos :: atts.toList + case x => List(x) + } + // Writing "Any" repeatedly to work within this structure + // is making my skin crawl. + def hasAttachment(x: Any) = attachments contains x + def withAttachment(att: Any): this.type = { attach(att); this } def detach(att: Any): Unit = detach(att.getClass) @@ -702,16 +719,13 @@ trait Trees { self: Universe => /** Identifier <name> */ case class Ident(name: Name) extends RefTree { def qualifier: Tree = EmptyTree + def isBackquoted = this hasAttachment BackquotedIdentifier } def Ident(name: String): Ident def Ident(sym: Symbol): Ident - // TODO remove this class, add a tree attachment to Ident to track whether it was backquoted - // copying trees will all too easily forget to distinguish subclasses - class BackQuotedIdent(name: Name) extends Ident(name) - /** Marks underlying reference to id as boxed. * @pre: id must refer to a captured variable * A reference such marked will refer to the boxed entity, no dereferencing @@ -1163,11 +1177,11 @@ trait Trees { self: Universe => new This(qual.toTypeName).copyAttrs(tree) def Select(tree: Tree, qualifier: Tree, selector: Name) = new Select(qualifier, selector).copyAttrs(tree) - def Ident(tree: Tree, name: Name) = - (tree match { // TODO: use a tree attachment to track whether this identifier was backquoted - case _ : BackQuotedIdent => new BackQuotedIdent(name) - case _ => new Ident(name) - }).copyAttrs(tree) + def Ident(tree: Tree, name: Name) = { + val t = new Ident(name) copyAttrs tree + if (tree hasAttachment BackquotedIdentifier) t withAttachment BackquotedIdentifier + else t + } def ReferenceToBoxed(tree: Tree, idt: Ident) = new ReferenceToBoxed(idt).copyAttrs(tree) def Literal(tree: Tree, value: Constant) = |