aboutsummaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2017-03-30 15:18:27 +0200
committerMartin Odersky <odersky@gmail.com>2017-04-11 09:33:11 +0200
commit6786cea6969b9a64bc4583f9c8fbd26bc8fbf372 (patch)
tree9302ac9191f0dc662dee835256f7fef0f66cbd44 /compiler
parentab2d095943dc63414da8352ebf1e82bdb642450d (diff)
downloaddotty-6786cea6969b9a64bc4583f9c8fbd26bc8fbf372.tar.gz
dotty-6786cea6969b9a64bc4583f9c8fbd26bc8fbf372.tar.bz2
dotty-6786cea6969b9a64bc4583f9c8fbd26bc8fbf372.zip
Make field names semantic
Diffstat (limited to 'compiler')
-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.scala8
4 files changed, 12 insertions, 22 deletions
diff --git a/compiler/src/dotty/tools/dotc/core/NameKinds.scala b/compiler/src/dotty/tools/dotc/core/NameKinds.scala
index f5a758256..706320938 100644
--- a/compiler/src/dotty/tools/dotc/core/NameKinds.scala
+++ b/compiler/src/dotty/tools/dotc/core/NameKinds.scala
@@ -249,6 +249,7 @@ object NameKinds {
val ProtectedSetterName = new PrefixNameKind(PROTECTEDSETTER, "protected$set") // dubious encoding, kept for Scala2 compatibility
val AvoidClashName = new SuffixNameKind(AVOIDCLASH, "$_avoid_name_clash_$")
val DirectName = new SuffixNameKind(DIRECT, "$direct")
+ val FieldName = new SuffixNameKind(FIELD, "$$local")
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 01ce4807c..ac6bfcca3 100644
--- a/compiler/src/dotty/tools/dotc/core/NameOps.scala
+++ b/compiler/src/dotty/tools/dotc/core/NameOps.scala
@@ -62,7 +62,6 @@ object NameOps {
def isReplWrapperName = name.toSimpleName containsSlice INTERPRETER_IMPORT_WRAPPER
def isSetterName = name endsWith SETTER_SUFFIX
def isImportName = name startsWith IMPORT
- def isFieldName = name endsWith LOCAL_SUFFIX
def isScala2LocalSuffix = name.endsWith(" ")
def isModuleVarName(name: Name): Boolean =
name.stripAnonNumberSuffix endsWith MODULE_VAR_SUFFIX
@@ -347,33 +346,22 @@ object NameOps {
implicit class TermNameDecorator(val name: TermName) extends AnyVal {
import nme._
- def setterName: TermName =
- if (name.isFieldName) name.fieldToGetter.setterName
- else name ++ SETTER_SUFFIX
+ def setterName: TermName = name.exclude(FieldName) ++ SETTER_SUFFIX
def getterName: TermName =
- if (name.isFieldName) fieldToGetter
- else setterToGetter
+ name.exclude(FieldName).mapLast(n =>
+ if (n.endsWith(SETTER_SUFFIX)) n.take(n.length - SETTER_SUFFIX.length).asSimpleName
+ else n)
def fieldName: TermName =
if (name.isSetterName) {
if (name.is(TraitSetterName)) {
- val TraitSetterName(_, original) = name
+ val TraitSetterName(_, original) = name
original.fieldName
}
else getterName.fieldName
}
- else name.mapLast(n => (n ++ LOCAL_SUFFIX).asSimpleName)
-
- private def setterToGetter: TermName = {
- assert(name.endsWith(SETTER_SUFFIX), name + " is referenced as a setter but has wrong name format")
- name.mapLast(n => n.take(n.length - SETTER_SUFFIX.length).asSimpleName)
- }
-
- def fieldToGetter: TermName = {
- assert(name.isFieldName)
- name.mapLast(n => n.take(n.length - LOCAL_SUFFIX.length).asSimpleName)
- }
+ else FieldName(name)
/** Nominally, name from name$default$N, CONSTRUCTOR for <init> */
def defaultGetterToMethod: TermName =
diff --git a/compiler/src/dotty/tools/dotc/core/StdNames.scala b/compiler/src/dotty/tools/dotc/core/StdNames.scala
index ece3d42dd..784a39fd8 100644
--- a/compiler/src/dotty/tools/dotc/core/StdNames.scala
+++ b/compiler/src/dotty/tools/dotc/core/StdNames.scala
@@ -240,7 +240,6 @@ object StdNames {
val FAKE_LOCAL_THIS: N = "this$"
val LAZY_FIELD_OFFSET: N = "OFFSET$"
val LAZY_SLOW_SUFFIX: N = "$lzycompute"
- val LOCAL_SUFFIX: N = "$$local"
val UNIVERSE_BUILD_PREFIX: N = "$u.build."
val UNIVERSE_BUILD: N = "$u.build"
val UNIVERSE_PREFIX: N = "$u."
diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala b/compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala
index 4acadc943..602bdeb02 100644
--- a/compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala
+++ b/compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala
@@ -234,9 +234,11 @@ object TastyFormat {
final val PROTECTEDSETTER = 22
final val INITIALIZER = 23
final val SHADOWED = 24
- final val AVOIDCLASH = 27
- final val DIRECT = 28
- final val OBJECTCLASS = 29
+ final val AVOIDCLASH = 30
+ final val DIRECT = 31
+ final val FIELD = 32
+ final val SETTER = 33
+ final val OBJECTCLASS = 40
final val SIGNED = 63
final val firstInternalTag = 64