From 47158c9ae592bab53b9618b90b2514166a8a6004 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sun, 26 Mar 2017 12:57:28 +0200 Subject: Properly integrate TraitSetter names --- compiler/src/dotty/tools/dotc/core/NameInfos.scala | 21 ++++++++++++++------- compiler/src/dotty/tools/dotc/core/NameOps.scala | 18 +++++++++++++----- .../dotty/tools/dotc/core/tasty/TreePickler.scala | 2 +- 3 files changed, 28 insertions(+), 13 deletions(-) (limited to 'compiler') diff --git a/compiler/src/dotty/tools/dotc/core/NameInfos.scala b/compiler/src/dotty/tools/dotc/core/NameInfos.scala index 23a161756..4f2628a9e 100644 --- a/compiler/src/dotty/tools/dotc/core/NameInfos.scala +++ b/compiler/src/dotty/tools/dotc/core/NameInfos.scala @@ -19,11 +19,14 @@ object NameInfo { type Kind = Int val TermNameKind = 0 - val QualifiedKind = 1 - val DefaultGetterKind = 3 - val VariantKind = 4 - val SuperAccessorKind = 5 - val InitializerKind = 6 + val SelectKind = 1 + val FlattenKind = 2 + val ExpandKind = 3 + val TraitSetterKind = 4 + val DefaultGetterKind = 5 + val VariantKind = 6 + val SuperAccessorKind = 7 + val InitializerKind = 8 val ModuleClassKind = 10 val qualifier: Map[String, SimpleTermName => Qualified] = @@ -32,7 +35,7 @@ object NameInfo { str.EXPAND_SEPARATOR -> Expand, str.TRAIT_SETTER_SEPARATOR -> TraitSetter) - def definesNewName(kind: Kind) = kind <= QualifiedKind + def definesNewName(kind: Kind) = kind <= TraitSetterKind /** TermNames have the lowest possible kind */ val TermName = new NameInfo { @@ -41,32 +44,36 @@ object NameInfo { } trait Qualified extends NameInfo { + def kind: Kind def name: SimpleTermName def separator: String def newLikeThis(name: SimpleTermName): Qualified // TODO: should use copy instead after bootstrap - def kind = QualifiedKind override def map(f: SimpleTermName => SimpleTermName): NameInfo = newLikeThis(f(name)) def mkString(underlying: TermName) = s"$underlying$separator$name" override def toString = s"${getClass.getSimpleName}($name)" } case class Select(val name: SimpleTermName) extends Qualified { + def kind = SelectKind def separator = "." def newLikeThis(name: SimpleTermName) = Select(name) } case class Flatten(val name: SimpleTermName) extends Qualified { + def kind = FlattenKind def separator = "$" def newLikeThis(name: SimpleTermName) = Flatten(name) } case class Expand(val name: SimpleTermName) extends Qualified { + def kind = ExpandKind def separator = str.EXPAND_SEPARATOR def newLikeThis(name: SimpleTermName) = Expand(name) } case class TraitSetter(val name: SimpleTermName) extends Qualified { + def kind = TraitSetterKind def separator = nme.TRAIT_SETTER_SEPARATOR.toString def newLikeThis(name: SimpleTermName) = TraitSetter(name) } diff --git a/compiler/src/dotty/tools/dotc/core/NameOps.scala b/compiler/src/dotty/tools/dotc/core/NameOps.scala index 9d5d3bd6a..6d58a82bc 100644 --- a/compiler/src/dotty/tools/dotc/core/NameOps.scala +++ b/compiler/src/dotty/tools/dotc/core/NameOps.scala @@ -82,7 +82,9 @@ object NameOps { def isLoopHeaderLabel = (name startsWith WHILE_PREFIX) || (name startsWith DO_WHILE_PREFIX) def isProtectedAccessorName = name startsWith PROTECTED_PREFIX def isReplWrapperName = name.toSimpleName containsSlice INTERPRETER_IMPORT_WRAPPER - def isTraitSetterName = name.toSimpleName containsSlice TRAIT_SETTER_SEPARATOR + def isTraitSetterName = + if (Config.semanticNames) name.is(NameInfo.TraitSetterKind) + else name containsSlice TRAIT_SETTER_SEPARATOR def isSetterName = name endsWith SETTER_SUFFIX def isSingletonName = name endsWith SINGLETON_SUFFIX def isModuleClassName = @@ -437,10 +439,16 @@ object NameOps { def fieldName: TermName = if (name.isSetterName) { if (name.isTraitSetterName) { - // has form <$-separated-trait-name>$_setter_$ `name`_$eq - val start = name.lastPart.indexOfSlice(TRAIT_SETTER_SEPARATOR) + TRAIT_SETTER_SEPARATOR.length - val end = name.lastPart.indexOfSlice(SETTER_SUFFIX) - name.mapLast(n => (n.slice(start, end) ++ LOCAL_SUFFIX).asSimpleName) + if (Config.semanticNames) { + val DerivedTermName(_, NameInfo.TraitSetter(original)) = name + original ++ LOCAL_SUFFIX + } + else { + // has form <$-separated-trait-name>$_setter_$ `name`_$eq + val start = name.indexOfSlice(TRAIT_SETTER_SEPARATOR) + TRAIT_SETTER_SEPARATOR.length + val end = name.indexOfSlice(SETTER_SUFFIX) + (name.slice(start, end) ++ LOCAL_SUFFIX).asTermName + } } else getterName.fieldName } else name.mapLast(n => (n ++ LOCAL_SUFFIX).asSimpleName) diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala index 34ce40cb0..e73d6ed0d 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala @@ -62,7 +62,7 @@ class TreePickler(pickler: TastyPickler) { private def pickleName(sym: Symbol)(implicit ctx: Context): Unit = { val nameRef = if (Config.semanticNames) { - if (sym is Flags.ExpandedName) assert(sym.name.is(NameInfo.QualifiedKind)) + if (sym is Flags.ExpandedName) assert(sym.name.is(NameInfo.ExpandKind)) nameIndex(sym.name) } else { -- cgit v1.2.3