aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2017-03-24 19:15:51 +0100
committerMartin Odersky <odersky@gmail.com>2017-04-11 09:33:10 +0200
commit0755ec28d22798c51aedf45e4dcdf1ed299c2aa5 (patch)
tree06b8b8f94005a9380d76c42880239fe282be268b
parent0ad1cd816bc1537ad332addabb0ff6c293e3e0a0 (diff)
downloaddotty-0755ec28d22798c51aedf45e4dcdf1ed299c2aa5.tar.gz
dotty-0755ec28d22798c51aedf45e4dcdf1ed299c2aa5.tar.bz2
dotty-0755ec28d22798c51aedf45e4dcdf1ed299c2aa5.zip
Add Variant NameInfo
Plus further bug fixes.
-rw-r--r--compiler/src/dotty/tools/dotc/core/NameInfos.scala12
-rw-r--r--compiler/src/dotty/tools/dotc/core/Names.scala3
-rw-r--r--compiler/src/dotty/tools/dotc/core/StdNames.scala2
-rw-r--r--compiler/src/dotty/tools/dotc/core/SymDenotations.scala24
-rw-r--r--compiler/src/dotty/tools/dotc/core/tasty/NameBuffer.scala5
-rw-r--r--compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala6
-rw-r--r--compiler/src/dotty/tools/dotc/core/tasty/TastyName.scala1
-rw-r--r--compiler/src/dotty/tools/dotc/core/tasty/TastyUnpickler.scala2
-rw-r--r--compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala1
-rw-r--r--compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala1
-rw-r--r--compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala6
11 files changed, 42 insertions, 21 deletions
diff --git a/compiler/src/dotty/tools/dotc/core/NameInfos.scala b/compiler/src/dotty/tools/dotc/core/NameInfos.scala
index c5b83b0dc..f6d9e84c0 100644
--- a/compiler/src/dotty/tools/dotc/core/NameInfos.scala
+++ b/compiler/src/dotty/tools/dotc/core/NameInfos.scala
@@ -20,8 +20,9 @@ object NameInfo {
val TermNameKind = 0
val QualifiedKind = 1
- val ModuleClassKind = 2
val DefaultGetterKind = 3
+ val VariantKind = 4
+ val ModuleClassKind = 10
val qualifier: Map[String, SimpleTermName => Qualified] =
Map("." -> Select,
@@ -81,9 +82,18 @@ object NameInfo {
}
}
+ case class Variant(val num: Int) extends Numbered {
+ def kind = VariantKind
+ def mkString(underlying: TermName) = varianceToPrefix(num).toString + underlying
+ }
+
val ModuleClass = new NameInfo {
def kind = ModuleClassKind
def mkString(underlying: TermName) = underlying + "$"
override def toString = "ModuleClass"
}
+
+ /** Map between variances and name prefixes */
+ val varianceToPrefix = Map(-1 -> '-', 0 -> '=', 1 -> '+')
+ val prefixToVariance = Map('-' -> -1, '=' -> 0, '+' -> 1)
} \ No newline at end of file
diff --git a/compiler/src/dotty/tools/dotc/core/Names.scala b/compiler/src/dotty/tools/dotc/core/Names.scala
index 22d0588f4..407dc149a 100644
--- a/compiler/src/dotty/tools/dotc/core/Names.scala
+++ b/compiler/src/dotty/tools/dotc/core/Names.scala
@@ -482,8 +482,9 @@ object Names {
val CONSTRUCTOR: TermName = termName("<init>")
val STATIC_CONSTRUCTOR: TermName = termName("<clinit>")
val EMPTY_PACKAGE: TermName = termName("<empty>")
+ val REFINEMENT: TermName = termName("<refinement>")
- val dontEncode = Set(CONSTRUCTOR, EMPTY_PACKAGE)
+ val dontEncode = Set(CONSTRUCTOR, EMPTY_PACKAGE, REFINEMENT)
def termNameBuilder: Builder[Char, TermName] =
StringBuilder.newBuilder.mapResult(termName)
diff --git a/compiler/src/dotty/tools/dotc/core/StdNames.scala b/compiler/src/dotty/tools/dotc/core/StdNames.scala
index 1a65556ba..e5e2165ce 100644
--- a/compiler/src/dotty/tools/dotc/core/StdNames.scala
+++ b/compiler/src/dotty/tools/dotc/core/StdNames.scala
@@ -548,7 +548,7 @@ object StdNames {
val nothingClass: N = "Nothing$"
val nullClass: N = "Null$"
-
+
val falseModuleClassNames = Set(nothingClass, nullClass, nothingRuntimeClass, nullRuntimeClass)
// unencoded operators
diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala
index 74505d811..e50d6a133 100644
--- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala
+++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala
@@ -393,21 +393,18 @@ object SymDenotations {
* enclosing packages do not form part of the name.
*/
def fullNameSeparated(separator: String)(implicit ctx: Context): Name = {
- var sep = separator
- var stopAtPackage = false
- if (sep.isEmpty) {
- sep = "$"
- stopAtPackage = true
- }
+ val stopAtPackage = separator.isEmpty
+ val sep = if (stopAtPackage) "$" else separator
if (symbol == NoSymbol ||
owner == NoSymbol ||
owner.isEffectiveRoot ||
stopAtPackage && owner.is(PackageClass)) name
else {
+ var filler = ""
var encl = owner
while (!encl.isClass && !encl.isPackageObject) {
encl = encl.owner
- sep += "~"
+ filler += "~"
}
var prefix = encl.fullNameSeparated(separator)
val fn =
@@ -416,14 +413,17 @@ object SymDenotations {
// duplicate scalac's behavior: don't write a double '$$' for module class members.
prefix = prefix.exclude(NameInfo.ModuleClassKind)
name rewrite {
- case n: SimpleTermName => prefix.derived(NameInfo.qualifier(sep)(n))
+ case n: SimpleTermName =>
+ val n1 = if (filler.isEmpty) n else termName(filler ++ n)
+ prefix.derived(NameInfo.qualifier(sep)(n1))
}
}
else {
- if (owner.is(ModuleClass, butNot = Package) && sep == "$")
- // duplicate scalac's behavior: don't write a double '$$' for module class members.
- sep = ""
- prefix ++ sep ++ name
+ val sep1 =
+ if (owner.is(ModuleClass, butNot = Package) && sep == "$") ""
+ else sep
+ // duplicate scalac's behavior: don't write a double '$$' for module class members.
+ prefix ++ sep1 ++ name
}
if (isType) fn.toTypeName else fn.toTermName
}
diff --git a/compiler/src/dotty/tools/dotc/core/tasty/NameBuffer.scala b/compiler/src/dotty/tools/dotc/core/tasty/NameBuffer.scala
index b45255eb8..19eb731c7 100644
--- a/compiler/src/dotty/tools/dotc/core/tasty/NameBuffer.scala
+++ b/compiler/src/dotty/tools/dotc/core/tasty/NameBuffer.scala
@@ -38,6 +38,8 @@ class NameBuffer extends TastyBuffer(10000) {
tcon(nameIndex(prefix, toTasty), nameIndex(qual.name))
case DerivedTermName(prefix, NameInfo.DefaultGetter(num)) =>
DefaultGetter(nameIndex(prefix, toTasty), num)
+ case DerivedTermName(prefix, NameInfo.Variant(sign)) =>
+ Variant(nameIndex(prefix, toTasty), sign)
case name1 =>
if (name1.isShadowedName) Shadowed(nameIndex(name1.revertShadowed, toTasty))
else toTasty(name1.asSimpleName)
@@ -102,6 +104,9 @@ class NameBuffer extends TastyBuffer(10000) {
case Shadowed(original) =>
writeByte(SHADOWED)
withLength { writeNameRef(original) }
+ case Variant(original, sign) =>
+ writeByte(VARIANT)
+ withLength { writeNameRef(original); writeNat(sign + 1) }
}
override def assemble(): Unit = {
diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala b/compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala
index 848b7995f..d4f6782fb 100644
--- a/compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala
+++ b/compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala
@@ -229,6 +229,7 @@ object TastyFormat {
final val SUPERACCESSOR = 7
final val DEFAULTGETTER = 8
final val SHADOWED = 9
+ final val VARIANT = 10
// AST tags
@@ -412,11 +413,14 @@ object TastyFormat {
def nameTagToString(tag: Int): String = tag match {
case UTF8 => "UTF8"
case QUALIFIED => "QUALIFIED"
- case SIGNED => "SIGNED"
+ case FLATTENED => "FLATTENED"
case EXPANDED => "EXPANDED"
+ case SIGNED => "SIGNED"
case OBJECTCLASS => "OBJECTCLASS"
case SUPERACCESSOR => "SUPERACCESSOR"
case DEFAULTGETTER => "DEFAULTGETTER"
+ case SHADOWED => "SHADOWED"
+ case VARIANT => "VARIANT"
}
def astTagToString(tag: Int): String = tag match {
diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TastyName.scala b/compiler/src/dotty/tools/dotc/core/tasty/TastyName.scala
index 67b08a1c1..769ecfbfc 100644
--- a/compiler/src/dotty/tools/dotc/core/tasty/TastyName.scala
+++ b/compiler/src/dotty/tools/dotc/core/tasty/TastyName.scala
@@ -21,6 +21,7 @@ object TastyName {
case class SuperAccessor(accessed: NameRef) extends TastyName
case class DefaultGetter(method: NameRef, num: Int) extends TastyName
case class Shadowed(original: NameRef) extends TastyName
+ case class Variant(original: NameRef, sign: Int) extends TastyName
class Table extends (NameRef => TastyName) {
private val names = new mutable.ArrayBuffer[TastyName]
diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TastyUnpickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TastyUnpickler.scala
index c8c1878bc..e6b43e6b4 100644
--- a/compiler/src/dotty/tools/dotc/core/tasty/TastyUnpickler.scala
+++ b/compiler/src/dotty/tools/dotc/core/tasty/TastyUnpickler.scala
@@ -62,6 +62,8 @@ class TastyUnpickler(reader: TastyReader) {
DefaultGetter(readNameRef(), readNat())
case SHADOWED =>
Shadowed(readNameRef())
+ case VARIANT =>
+ Variant(readNameRef(), readNat() - 1)
}
assert(currentAddr == end, s"bad name $result $start $currentAddr $end")
result
diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala
index 78d59c99f..d81bd3ea8 100644
--- a/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala
+++ b/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala
@@ -13,6 +13,7 @@ import NameOps._
import StdNames.nme
import TastyBuffer._
import TypeApplications._
+import config.Config
class TreePickler(pickler: TastyPickler) {
val buf = new TreeBuffer
diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala
index d4269d6e4..14c3d7cd1 100644
--- a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala
+++ b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala
@@ -91,6 +91,7 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table, posUnpickle
case ModuleClass(original) => toTermName(original).moduleClassName.toTermName
case SuperAccessor(accessed) => toTermName(accessed).superName
case DefaultGetter(meth, num) => toTermName(meth).defaultGetterName(num)
+ case Variant(original, sign) => toTermName(original).derived(NameInfo.Variant(sign))
}
private def qualTermName(qual: NameRef, name: NameRef, sep: String) =
diff --git a/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala b/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala
index c762bbeaf..20e657ce7 100644
--- a/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala
+++ b/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala
@@ -97,11 +97,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
|| (sym.name == nme.PACKAGE) // package
)
- def nameString(name: Name): String = name.toString + {
- if (ctx.settings.debugNames.value)
- if (name.isTypeName) "/T" else "/V"
- else ""
- }
+ def nameString(name: Name): String = name.toString
def toText(name: Name): Text = Str(nameString(name))