summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2012-05-03 10:10:39 -0700
committerPaul Phillips <paulp@improving.org>2012-05-03 10:53:03 -0700
commit0cb886ae44505334dd5e8408b9355a53bc00e578 (patch)
tree41e66ce4b4265cf4a53e5774236d9248afcdf5dd
parentca74659bb06611b87474ffe2fd17b131cd3d34b0 (diff)
downloadscala-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.
-rw-r--r--src/compiler/scala/reflect/internal/Importers.scala8
-rw-r--r--src/compiler/scala/reflect/internal/StdNames.scala7
-rw-r--r--src/compiler/scala/reflect/internal/TreeInfo.scala7
-rw-r--r--src/compiler/scala/reflect/internal/TreePrinters.scala8
-rw-r--r--src/compiler/scala/tools/nsc/ast/parser/Parsers.scala6
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/RefChecks.scala1
-rw-r--r--src/library/scala/reflect/api/Trees.scala32
7 files changed, 42 insertions, 27 deletions
diff --git a/src/compiler/scala/reflect/internal/Importers.scala b/src/compiler/scala/reflect/internal/Importers.scala
index 8404386e10..6d6a0ec317 100644
--- a/src/compiler/scala/reflect/internal/Importers.scala
+++ b/src/compiler/scala/reflect/internal/Importers.scala
@@ -389,12 +389,8 @@ trait Importers { self: SymbolTable =>
new This(importName(qual).toTypeName)
case from.Select(qual, name) =>
new Select(importTree(qual), importName(name))
- case from.Ident(name) => tree match {
- case _: from.BackQuotedIdent =>
- new BackQuotedIdent(importName(name))
- case _ =>
- new Ident(importName(name))
- }
+ case from.Ident(name) =>
+ new Ident(importName(name))
case from.ReferenceToBoxed(ident) =>
new ReferenceToBoxed(importTree(ident) match { case ident: Ident => ident })
case from.Literal(constant @ from.Constant(_)) =>
diff --git a/src/compiler/scala/reflect/internal/StdNames.scala b/src/compiler/scala/reflect/internal/StdNames.scala
index 5b91270de1..6413f0ea43 100644
--- a/src/compiler/scala/reflect/internal/StdNames.scala
+++ b/src/compiler/scala/reflect/internal/StdNames.scala
@@ -332,6 +332,11 @@ trait StdNames {
def isSingletonName(name: Name) = name endsWith SINGLETON_SUFFIX
def isModuleName(name: Name) = name endsWith MODULE_SUFFIX_NAME
+ def isDeprecatedIdentifierName(name: Name) = name.toTermName match {
+ case nme.`then` | nme.`macro` => true
+ case _ => false
+ }
+
def isOpAssignmentName(name: Name) = name match {
case raw.NE | raw.LE | raw.GE | EMPTY => false
case _ =>
@@ -634,6 +639,7 @@ trait StdNames {
val lang: NameType = "lang"
val length: NameType = "length"
val lengthCompare: NameType = "lengthCompare"
+ val `macro` : NameType = "macro"
val macroThis : NameType = "_this"
val macroContext : NameType = "c"
val main: NameType = "main"
@@ -690,6 +696,7 @@ trait StdNames {
val staticModule : NameType = "staticModule"
val synchronized_ : NameType = "synchronized"
val tail: NameType = "tail"
+ val `then` : NameType = "then"
val thisModuleType: NameType = "thisModuleType"
val this_ : NameType = "this"
val throw_ : NameType = "throw"
diff --git a/src/compiler/scala/reflect/internal/TreeInfo.scala b/src/compiler/scala/reflect/internal/TreeInfo.scala
index f4878139e9..2251310f35 100644
--- a/src/compiler/scala/reflect/internal/TreeInfo.scala
+++ b/src/compiler/scala/reflect/internal/TreeInfo.scala
@@ -227,8 +227,11 @@ abstract class TreeInfo {
/** Is tree a variable pattern? */
def isVarPattern(pat: Tree): Boolean = pat match {
- case _: BackQuotedIdent => false
- case x: Ident => isVariableName(x.name)
+ case x: Ident => !x.isBackquoted && isVariableName(x.name)
+ case _ => false
+ }
+ def isDeprecatedIdentifier(tree: Tree): Boolean = tree match {
+ case x: Ident => !x.isBackquoted && nme.isDeprecatedIdentifierName(x.name)
case _ => false
}
diff --git a/src/compiler/scala/reflect/internal/TreePrinters.scala b/src/compiler/scala/reflect/internal/TreePrinters.scala
index 3093bb049a..b3e4318fdc 100644
--- a/src/compiler/scala/reflect/internal/TreePrinters.scala
+++ b/src/compiler/scala/reflect/internal/TreePrinters.scala
@@ -373,11 +373,9 @@ trait TreePrinters extends api.TreePrinters { self: SymbolTable =>
case Select(qualifier, name) =>
print(backquotedPath(qualifier), ".", symName(tree, name))
- case bqid: BackQuotedIdent =>
- print("`%s`" format symName(tree, bqid.name))
-
- case Ident(name) =>
- print(symName(tree, name))
+ case id @ Ident(name) =>
+ val str = symName(tree, name)
+ print( if (id.isBackquoted) "`" + str + "`" else str )
case Literal(x) =>
print(x.escapedStringValue)
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
index 337ca7671c..c02a7e493e 100644
--- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
+++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
@@ -1027,7 +1027,7 @@ self =>
val tok = in.token
val name = ident()
t = atPos(start) {
- if (tok == BACKQUOTED_IDENT) new BackQuotedIdent(name)
+ if (tok == BACKQUOTED_IDENT) Ident(name) withAttachment BackquotedIdentifier
else Ident(name)
}
if (in.token == DOT) {
@@ -2506,7 +2506,6 @@ self =>
}
else {
val nameOffset = in.offset
- val isBackquoted = in.token == BACKQUOTED_IDENT
val name = ident()
funDefRest(start, nameOffset, mods, name)
}
@@ -2601,7 +2600,6 @@ self =>
newLinesOpt()
atPos(start, in.offset) {
val nameOffset = in.offset
- val isBackquoted = in.token == BACKQUOTED_IDENT
val name = identForType()
// @M! a type alias as well as an abstract type may declare type parameters
val tparams = typeParamClauseOpt(name, null)
@@ -2660,7 +2658,6 @@ self =>
def classDef(start: Int, mods: Modifiers): ClassDef = {
in.nextToken
val nameOffset = in.offset
- val isBackquoted = in.token == BACKQUOTED_IDENT
val name = identForType()
atPos(start, if (name == tpnme.ERROR) start else nameOffset) {
savingClassContextBounds {
@@ -2701,7 +2698,6 @@ self =>
def objectDef(start: Int, mods: Modifiers): ModuleDef = {
in.nextToken
val nameOffset = in.offset
- val isBackquoted = in.token == BACKQUOTED_IDENT
val name = ident()
val tstart = in.offset
atPos(start, if (name == nme.ERROR) start else nameOffset) {
diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
index 917542aa76..e60cda6af7 100644
--- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
@@ -1458,6 +1458,7 @@ abstract class RefChecks extends InfoTransform with reflect.internal.transform.R
analyzer.ImplicitNotFoundMsg.check(sym) foreach { warn =>
unit.warning(tree.pos, "Invalid implicitNotFound message for %s%s:\n%s".format(sym, sym.locationString, warn))
}
+
case tpt@TypeTree() =>
if(tpt.original != null) {
tpt.original foreach {
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) =