From a3f6ca5a5cd96e17d2f9a9c5187f45ff02b5dd61 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 31 Mar 2017 14:17:16 +0200 Subject: Make module var names semantic --- compiler/src/dotty/tools/dotc/core/NameKinds.scala | 1 + compiler/src/dotty/tools/dotc/core/NameOps.scala | 24 ++-------------------- compiler/src/dotty/tools/dotc/core/StdNames.scala | 1 - .../dotty/tools/dotc/core/tasty/TastyFormat.scala | 1 + .../dotty/tools/dotc/printing/PlainPrinter.scala | 3 +-- 5 files changed, 5 insertions(+), 25 deletions(-) (limited to 'compiler') 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 = " + tp.symbol.is(Module) || tp.symbol.name == nme.IMPORT => toTextRef(tp) ~ ".type" case tp: TermRef if tp.denot.isOverloaded => "" -- cgit v1.2.3