Skip to content

Fix/#560 #564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/dotty/tools/backend/jvm/DottyBackendInterface.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 ????
Expand Down
2 changes: 1 addition & 1 deletion src/dotty/tools/dotc/core/NameOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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`
*/
Expand Down
56 changes: 30 additions & 26 deletions src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 += "~"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does ~ stand for?

}
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 -------------------------------------------------

Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions src/dotty/tools/dotc/transform/Flatten.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 0 additions & 3 deletions src/dotty/tools/dotc/transform/SymUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down