From 4b82e83052de948c6a3b77c40892766421e259c2 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 13 May 2015 16:56:33 +0200 Subject: [PATCH 1/2] Put ScalaRunTime into its proper place. Eclipse freaked out because ScalaRunTime was in the ScalaRunTime directroy, whereas it should have been in runtime. --- src/scala/runtime/{ScalaRunTime => }/ScalaRunTime.scala | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/scala/runtime/{ScalaRunTime => }/ScalaRunTime.scala (100%) diff --git a/src/scala/runtime/ScalaRunTime/ScalaRunTime.scala b/src/scala/runtime/ScalaRunTime.scala similarity index 100% rename from src/scala/runtime/ScalaRunTime/ScalaRunTime.scala rename to src/scala/runtime/ScalaRunTime.scala From 45521484c5acb8f3174aebcd23674c0af955dc06 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 13 May 2015 17:43:39 +0200 Subject: [PATCH 2/2] Fix #560 - refactor flatName - Merge flatName and fullNameSeparated - Treat nested members of modules specially, to conform to scalac conventions - Use `~` as separator for term members. --- .../backend/jvm/DottyBackendInterface.scala | 2 +- src/dotty/tools/dotc/core/NameOps.scala | 2 +- .../tools/dotc/core/SymDenotations.scala | 56 ++++++++++--------- src/dotty/tools/dotc/transform/Flatten.scala | 3 +- src/dotty/tools/dotc/transform/SymUtils.scala | 3 - 5 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/dotty/tools/backend/jvm/DottyBackendInterface.scala b/src/dotty/tools/backend/jvm/DottyBackendInterface.scala index a72ed1130fb3..b2f111dbe61a 100644 --- a/src/dotty/tools/backend/jvm/DottyBackendInterface.scala +++ b/src/dotty/tools/backend/jvm/DottyBackendInterface.scala @@ -554,7 +554,7 @@ class DottyBackendInterface()(implicit ctx: Context) extends BackendInterface{ def fullName: String = sym.showFullName def simpleName: Name = sym.name def javaSimpleName: Name = toDenot(sym).name // addModuleSuffix(simpleName.dropLocal) - def javaBinaryName: Name = toDenot(sym).fullNameSeparated('/') // addModuleSuffix(fullNameInternal('/')) + def javaBinaryName: Name = toDenot(sym).fullNameSeparated("/") // addModuleSuffix(fullNameInternal('/')) def javaClassName: String = toDenot(sym).fullName.toString// addModuleSuffix(fullNameInternal('.')).toString def name: Name = sym.name def rawname: Name = sym.name // todo ???? diff --git a/src/dotty/tools/dotc/core/NameOps.scala b/src/dotty/tools/dotc/core/NameOps.scala index ebf016acc1e4..60aacd8949af 100644 --- a/src/dotty/tools/dotc/core/NameOps.scala +++ b/src/dotty/tools/dotc/core/NameOps.scala @@ -150,7 +150,7 @@ object NameOps { /** The expanded name of `name` relative to given class `base`. */ def expandedName(base: Symbol)(implicit ctx: Context): N = - expandedName(if (base is Flags.ExpandedName) base.name else base.fullNameSeparated('$')) + expandedName(if (base is Flags.ExpandedName) base.name else base.fullNameSeparated("$")) /** The expanded name of `name` relative to `basename` with given `separator` */ diff --git a/src/dotty/tools/dotc/core/SymDenotations.scala b/src/dotty/tools/dotc/core/SymDenotations.scala index 1ad718c292c2..f3067f4cbd61 100644 --- a/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/src/dotty/tools/dotc/core/SymDenotations.scala @@ -289,39 +289,43 @@ object SymDenotations { } /** The encoded full path name of this denotation, where outer names and inner names - * are separated by `separator` characters. + * are separated by `separator` strings. * Never translates expansions of operators back to operator symbol. - * Drops package objects. Represents terms in the owner chain by a simple `separator`. + * Drops package objects. Represents terms in the owner chain by a simple `~`. + * (Note: scalac uses nothing to represent terms, which can cause name clashes + * between same-named definitions in different enclosing methods. Before this commit + * we used `$' but this can cause ambiguities with the class separator '$'). + * A separator "" means "flat name"; the real separator in this case is "$" and + * enclosing packages do not form part of the name. */ - def fullNameSeparated(separator: Char)(implicit ctx: Context): Name = - if (symbol == NoSymbol || owner == NoSymbol || owner.isEffectiveRoot) name + def fullNameSeparated(separator: String)(implicit ctx: Context): Name = { + var sep = separator + var stopAtPackage = false + if (sep.isEmpty) { + sep = "$" + stopAtPackage = true + } + if (symbol == NoSymbol || + owner == NoSymbol || + owner.isEffectiveRoot || + stopAtPackage && owner.is(PackageClass)) name else { - var owner = this - var sep = "" - do { - owner = owner.owner - sep += separator - } while (!owner.isClass && !owner.isPackageObject) - val fn = owner.fullNameSeparated(separator) ++ sep ++ name + var encl = owner + while (!encl.isClass && !encl.isPackageObject) { + encl = encl.owner + sep += "~" + } + if (owner.is(ModuleClass) && sep == "$") sep = "" // duplicate scalac's behavior: don't write a double '$$' for module class members. + val fn = encl.fullNameSeparated(separator) ++ sep ++ name if (isType) fn.toTypeName else fn.toTermName } + } /** The encoded flat name of this denotation, where joined names are separated by `separator` characters. */ - def flatName(separator: Char = '$')(implicit ctx: Context): Name = - if (symbol == NoSymbol || owner == NoSymbol || owner.isEffectiveRoot || (owner is PackageClass)) name - else { - var owner = this - var sep = "" - do { - owner = owner.owner - sep += separator - } while (!owner.isClass && !owner.isPackageObject) - val fn = owner.flatName(separator) ++ sep ++ name - if (isType) fn.toTypeName else fn.toTermName - } + def flatName(implicit ctx: Context): Name = fullNameSeparated("") /** `fullName` where `.' is the separator character */ - def fullName(implicit ctx: Context): Name = fullNameSeparated('.') + def fullName(implicit ctx: Context): Name = fullNameSeparated(".") // ----- Tests ------------------------------------------------- @@ -1572,8 +1576,8 @@ object SymDenotations { } } - private[this] var fullNameCache: SimpleMap[Character, Name] = SimpleMap.Empty - override final def fullNameSeparated(separator: Char)(implicit ctx: Context): Name = { + private[this] var fullNameCache: SimpleMap[String, Name] = SimpleMap.Empty + override final def fullNameSeparated(separator: String)(implicit ctx: Context): Name = { val cached = fullNameCache(separator) if (cached != null) cached else { diff --git a/src/dotty/tools/dotc/transform/Flatten.scala b/src/dotty/tools/dotc/transform/Flatten.scala index 0bd1bb75fdd4..9a047ef9589e 100644 --- a/src/dotty/tools/dotc/transform/Flatten.scala +++ b/src/dotty/tools/dotc/transform/Flatten.scala @@ -6,7 +6,6 @@ import DenotTransformers.SymTransformer import Phases.Phase import Contexts.Context import Flags._ -import SymUtils._ import SymDenotations.SymDenotation import collection.mutable import TreeTransforms.MiniPhaseTransform @@ -19,7 +18,7 @@ class Flatten extends MiniPhaseTransform with SymTransformer { thisTransform => def transformSym(ref: SymDenotation)(implicit ctx: Context) = { if (ref.isClass && !ref.is(Package) && !ref.owner.is(Package)) { ref.copySymDenotation( - name = ref.flatName(), + name = ref.flatName, owner = ref.enclosingPackageClass) } else ref diff --git a/src/dotty/tools/dotc/transform/SymUtils.scala b/src/dotty/tools/dotc/transform/SymUtils.scala index 9b4b0660126a..df3b183a956b 100644 --- a/src/dotty/tools/dotc/transform/SymUtils.scala +++ b/src/dotty/tools/dotc/transform/SymUtils.scala @@ -85,9 +85,6 @@ class SymUtils(val self: Symbol) extends AnyVal { def field(implicit ctx: Context): Symbol = self.owner.info.decl(self.asTerm.name.fieldName).suchThat(!_.is(Method)).symbol - /** `fullName` where `$' is the separator character */ - def flatName(implicit ctx: Context): Name = self.flatName('$') - def initializer(implicit ctx: Context): TermSymbol = self.owner.info.decl(InitializerName(self.asTerm.name)).symbol.asTerm