aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2017-03-31 14:17:16 +0200
committerMartin Odersky <odersky@gmail.com>2017-04-11 09:33:12 +0200
commita3f6ca5a5cd96e17d2f9a9c5187f45ff02b5dd61 (patch)
tree5c6180be4cb80978555ebe99ac0f00837e77e70f
parente3e5e79e24503a2e6be7f708d81c27068664b893 (diff)
downloaddotty-a3f6ca5a5cd96e17d2f9a9c5187f45ff02b5dd61.tar.gz
dotty-a3f6ca5a5cd96e17d2f9a9c5187f45ff02b5dd61.tar.bz2
dotty-a3f6ca5a5cd96e17d2f9a9c5187f45ff02b5dd61.zip
Make module var names semantic
-rw-r--r--compiler/src/dotty/tools/dotc/core/NameKinds.scala1
-rw-r--r--compiler/src/dotty/tools/dotc/core/NameOps.scala24
-rw-r--r--compiler/src/dotty/tools/dotc/core/StdNames.scala1
-rw-r--r--compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala1
-rw-r--r--compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala3
5 files changed, 5 insertions, 25 deletions
diff --git a/compiler/src/dotty/tools/dotc/core/NameKinds.scala b/compiler/src/dotty/tools/dotc/core/NameKinds.scala
index 706320938..8279c21bb 100644
--- a/compiler/src/dotty/tools/dotc/core/NameKinds.scala
+++ b/compiler/src/dotty/tools/dotc/core/NameKinds.scala
@@ -250,6 +250,7 @@ object NameKinds {
val AvoidClashName = new SuffixNameKind(AVOIDCLASH, "$_avoid_name_clash_$")
val DirectName = new SuffixNameKind(DIRECT, "$direct")
val FieldName = new SuffixNameKind(FIELD, "$$local")
+ val ModuleVarName = new SuffixNameKind(OBJECTVAR, "$module")
val ModuleClassName = new SuffixNameKind(OBJECTCLASS, "$", optInfoString = "ModuleClass")
object SignedName extends NameKind(63) {
diff --git a/compiler/src/dotty/tools/dotc/core/NameOps.scala b/compiler/src/dotty/tools/dotc/core/NameOps.scala
index 39981543d..b262fb536 100644
--- a/compiler/src/dotty/tools/dotc/core/NameOps.scala
+++ b/compiler/src/dotty/tools/dotc/core/NameOps.scala
@@ -57,15 +57,13 @@ object NameOps {
def isConstructorName = name == CONSTRUCTOR || name == TRAIT_CONSTRUCTOR
def isStaticConstructorName = name == STATIC_CONSTRUCTOR
- def isImplClassName = name endsWith IMPL_CLASS_SUFFIX
def isLocalDummyName = name startsWith LOCALDUMMY_PREFIX
def isReplWrapperName = name.toSimpleName containsSlice INTERPRETER_IMPORT_WRAPPER
def isSetterName = name endsWith SETTER_SUFFIX
def isImportName = name startsWith IMPORT
def isScala2LocalSuffix = name.endsWith(" ")
- def isModuleVarName(name: Name): Boolean =
- name.stripAnonNumberSuffix endsWith MODULE_VAR_SUFFIX
- def isSelectorName = name.startsWith(" ") && name.tail.forall(_.isDigit)
+ def isModuleVarName(name: Name): Boolean = name.exclude(UniqueName).is(ModuleVarName)
+ def isSelectorName = name.startsWith("_") && name.tail.forall(_.isDigit)
def isOuterSelect = name.endsWith(nme.OUTER_SELECT)
/** Is name a variable name? */
@@ -86,21 +84,6 @@ object NameOps {
false
}
- /** If the name ends with $nn where nn are
- * all digits, strip the $ and the digits.
- * Otherwise return the argument.
- */
- def stripAnonNumberSuffix: Name = {
- var pos = name.length
- while (pos > 0 && name(pos - 1).isDigit)
- pos -= 1
-
- if (pos > 0 && pos < name.length && name(pos - 1) == '$')
- name take (pos - 1)
- else
- name
- }
-
/** Convert this module name to corresponding module class name */
def moduleClassName: TypeName = name.derived(ModuleClassName).toTypeName
@@ -378,9 +361,6 @@ object NameOps {
def stripScala2LocalSuffix: TermName =
if (name.isScala2LocalSuffix) name.init.asTermName else name
- def moduleVarName: TermName =
- name ++ MODULE_VAR_SUFFIX
-
/** The name unary_x for a prefix operator x */
def toUnaryName: TermName = name match {
case raw.MINUS => UNARY_-
diff --git a/compiler/src/dotty/tools/dotc/core/StdNames.scala b/compiler/src/dotty/tools/dotc/core/StdNames.scala
index 784a39fd8..b89775e9e 100644
--- a/compiler/src/dotty/tools/dotc/core/StdNames.scala
+++ b/compiler/src/dotty/tools/dotc/core/StdNames.scala
@@ -117,7 +117,6 @@ object StdNames {
val INTERPRETER_WRAPPER_SUFFIX: N = "$object"
val LOCALDUMMY_PREFIX: N = "<local " // owner of local blocks
val MODULE_SUFFIX: N = NameTransformer.MODULE_SUFFIX_STRING
- val MODULE_VAR_SUFFIX: N = "$module"
val NAME_JOIN: N = NameTransformer.NAME_JOIN_STRING
val OPS_PACKAGE: N = "<special-ops>"
val OVERLOADED: N = "<overloaded>"
diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala b/compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala
index d1997376d..04550f188 100644
--- a/compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala
+++ b/compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala
@@ -238,6 +238,7 @@ object TastyFormat {
final val DIRECT = 31
final val FIELD = 32
final val SETTER = 33
+ final val OBJECTVAR = 39
final val OBJECTCLASS = 40
final val SIGNED = 63
diff --git a/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala b/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala
index ec9257acf..375edc3cb 100644
--- a/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala
+++ b/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala
@@ -131,8 +131,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
toTextRHS(tp)
case tp: TermRef
if !tp.denotationIsCurrent && !homogenizedView || // always print underlying when testing picklers
- tp.symbol.is(Module) ||
- tp.symbol.name.isImportName =>
+ tp.symbol.is(Module) || tp.symbol.name == nme.IMPORT =>
toTextRef(tp) ~ ".type"
case tp: TermRef if tp.denot.isOverloaded =>
"<overloaded " ~ toTextRef(tp) ~ ">"