aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2017-03-28 13:07:11 +0200
committerMartin Odersky <odersky@gmail.com>2017-04-11 09:33:11 +0200
commit1e49ddad97c4e8207913857511ae62467f8cd3ce (patch)
tree9b5f38d746faec377c6778e902a627354808b05e
parent0021ffb0f1a0a857b7cdc8cdf769ae727dcb4b2c (diff)
downloaddotty-1e49ddad97c4e8207913857511ae62467f8cd3ce.tar.gz
dotty-1e49ddad97c4e8207913857511ae62467f8cd3ce.tar.bz2
dotty-1e49ddad97c4e8207913857511ae62467f8cd3ce.zip
Redefine definesNewName
Make it a method of info instead of a convention over tags, because it's less fragile that way. Also, add UniqueName extractor.
-rw-r--r--compiler/src/dotty/tools/dotc/core/NameExtractors.scala15
-rw-r--r--compiler/src/dotty/tools/dotc/core/Names.scala6
-rw-r--r--compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala5
3 files changed, 18 insertions, 8 deletions
diff --git a/compiler/src/dotty/tools/dotc/core/NameExtractors.scala b/compiler/src/dotty/tools/dotc/core/NameExtractors.scala
index 6045f0c10..2c5f5c164 100644
--- a/compiler/src/dotty/tools/dotc/core/NameExtractors.scala
+++ b/compiler/src/dotty/tools/dotc/core/NameExtractors.scala
@@ -16,6 +16,7 @@ object NameExtractors {
abstract class NameInfo extends DotClass {
def tag: Int
+ def definesNewName: Boolean = false
def mkString(underlying: TermName): String
def map(f: SimpleTermName => SimpleTermName): NameInfo = this
}
@@ -64,6 +65,7 @@ object NameExtractors {
abstract class QualifiedNameExtractor(tag: Int, val separator: String, val infoString: String) extends NameExtractor(tag) {
type ThisInfo = QualInfo
case class QualInfo(val name: SimpleTermName) extends Info with QualifiedInfo {
+ override def definesNewName = true
override def map(f: SimpleTermName => SimpleTermName): NameInfo = new QualInfo(f(name))
override def toString = s"$infoString $name"
}
@@ -89,9 +91,10 @@ object NameExtractors {
def num: Int
}
- abstract class NumberedNameExtractor(tag: Int, val infoString: String) extends NameExtractor(tag) {
+ abstract class NumberedNameExtractor(tag: Int, val infoString: String) extends NameExtractor(tag) { self =>
type ThisInfo = NumberedInfo
case class NumberedInfo(val num: Int) extends Info with NameExtractors.NumberedInfo {
+ override def definesNewName = self.definesNewName
override def toString = s"$infoString $num"
}
def apply(qual: TermName, num: Int) =
@@ -100,6 +103,14 @@ object NameExtractors {
case DerivedTermName(underlying, info: this.NumberedInfo) => Some((underlying, info.num))
case _ => None
}
+ def definesNewName = false
+ }
+
+ class UniqueNameExtractor(sep: String) extends NumberedNameExtractor(UNIQUE, "Unique") {
+ val separator = if (sep.isEmpty) "$" else sep
+ override def definesNewName = !sep.isEmpty
+ def mkString(underlying: TermName, info: ThisInfo) =
+ underlying.toString + separator + info.num
}
object QualifiedName extends QualifiedNameExtractor(QUALIFIED, ".", "Qualified")
@@ -148,8 +159,6 @@ object NameExtractors {
def infoString: String = "Signed"
}
- def definesNewName(tag: Int) = tag <= TraitSetterName.tag
-
def extractorOfTag(tag: Int) = extractors(tag)
val separatorToQualified: Map[String, QualifiedNameExtractor] =
diff --git a/compiler/src/dotty/tools/dotc/core/Names.scala b/compiler/src/dotty/tools/dotc/core/Names.scala
index d1788b6f9..81429a8d9 100644
--- a/compiler/src/dotty/tools/dotc/core/Names.scala
+++ b/compiler/src/dotty/tools/dotc/core/Names.scala
@@ -175,7 +175,7 @@ object Names {
*/
def derived(info: NameInfo): TermName = {
val ownTag = this.info.tag
- if (ownTag < info.tag || definesNewName(info.tag)) add(info)
+ if (ownTag < info.tag || info.definesNewName) add(info)
else if (ownTag > info.tag) rewrap(underlying.derived(info))
else {
assert(info == this.info)
@@ -185,7 +185,7 @@ object Names {
def exclude(kind: NameExtractor): TermName = {
val ownTag = this.info.tag
- if (ownTag < kind.tag || definesNewName(ownTag)) this
+ if (ownTag < kind.tag || info.definesNewName) this
else if (ownTag > kind.tag) rewrap(underlying.exclude(kind))
else underlying
}
@@ -193,7 +193,7 @@ object Names {
def is(kind: NameExtractor): Boolean = {
val ownTag = this.info.tag
ownTag == kind.tag ||
- !definesNewName(ownTag) && ownTag > kind.tag && underlying.is(kind)
+ !info.definesNewName && ownTag > kind.tag && underlying.is(kind)
}
override def hashCode = System.identityHashCode(this)
diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala b/compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala
index 792c11cee..d0fee04df 100644
--- a/compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala
+++ b/compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala
@@ -225,8 +225,9 @@ object TastyFormat {
final val FLATTENED = 3
final val EXPANDED = 4
final val TRAITSETTER = 5
- final val DEFAULTGETTER = 10
- final val VARIANT = 11
+ final val UNIQUE = 10
+ final val DEFAULTGETTER = 11
+ final val VARIANT = 12
final val SUPERACCESSOR = 20
final val INITIALIZER = 21
final val SHADOWED = 22