Skip to content

Commit

Permalink
Clean up logic using a new method replaceDeep
Browse files Browse the repository at this point in the history
  • Loading branch information
odersky committed Jul 21, 2022
1 parent 57fb5d4 commit 9f4871b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
3 changes: 1 addition & 2 deletions compiler/src/dotty/tools/dotc/core/NameOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,8 @@ object NameOps {

/** Revert the expanded name. */
def unexpandedName: N = likeSpacedN {
name.replace {
name.replaceDeep {
case ExpandedName(_, unexp) => unexp
case DerivedName(qual, info: QualifiedInfo) => qual.unexpandedName.derived(info)
}
}

Expand Down
9 changes: 8 additions & 1 deletion compiler/src/dotty/tools/dotc/core/Names.scala
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,18 @@ object Names {

/** Apply rewrite rule given by `f` to some part of this name, skipping and rewrapping
* other decorators.
* Stops at `DerivedName`s with infos of kind `QualifiedInfo`.
* Stops at DerivedNames with infos of kind QualifiedInfo.
* If `f` does not apply to any part, return name unchanged.
*/
def replace(f: PartialFunction[Name, Name]): ThisName

/** Same as replace, but does not stop at DerivedNames with infos of kind QualifiedInfo. */
def replaceDeep(f: PartialFunction[Name, Name]): ThisName =
replace(f.orElse {
case DerivedName(underlying, info: QualifiedInfo) =>
underlying.replaceDeep(f).derived(info)
})

/** If partial function `f` is defined for some part of this name, apply it
* in a Some, otherwise None.
* Stops at derived names whose kind has `definesNewName = true`.
Expand Down
11 changes: 3 additions & 8 deletions compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -486,15 +486,10 @@ object SymDenotations {
def qualify(n: SimpleName) =
val qn = kind(prefix.toTermName, if (filler.isEmpty) n else termName(filler + n))
if kind == FlatName && !encl.is(JavaDefined) then qn.compactified else qn
def expand(name: Name): Name = name.replace {
case name: SimpleName => qualify(name)
case name @ DerivedName(qual, info: QualifiedInfo) =>
expand(qual).derived(info)
// Keep the qualified name, so that it can be recovered later.
// An example where this matters is run/i15702.scala
val fn = name.replaceDeep {
case n: SimpleName => qualify(n)
}
val fn = expand(name)
if (name.isTypeName) fn.toTypeName else fn.toTermName
if name.isTypeName then fn.toTypeName else fn.toTermName
}

/** The encoded flat name of this denotation, where joined names are separated by `separator` characters. */
Expand Down

0 comments on commit 9f4871b

Please sign in to comment.