diff options
Diffstat (limited to 'compiler/src/dotty/tools/dotc/util')
-rw-r--r-- | compiler/src/dotty/tools/dotc/util/FreshNameCreator.scala | 17 | ||||
-rw-r--r-- | compiler/src/dotty/tools/dotc/util/NameTransformer.scala | 5 |
2 files changed, 12 insertions, 10 deletions
diff --git a/compiler/src/dotty/tools/dotc/util/FreshNameCreator.scala b/compiler/src/dotty/tools/dotc/util/FreshNameCreator.scala index 8892a570e..5dbec3e5a 100644 --- a/compiler/src/dotty/tools/dotc/util/FreshNameCreator.scala +++ b/compiler/src/dotty/tools/dotc/util/FreshNameCreator.scala @@ -3,9 +3,12 @@ package dotc package util import scala.collection.mutable +import core.Names.TermName +import core.NameKinds.UniqueNameKind +import core.StdNames.str -trait FreshNameCreator { - def newName(prefix: String = ""): String +abstract class FreshNameCreator { + def newName(prefix: TermName, unique: UniqueNameKind): TermName } object FreshNameCreator { @@ -18,11 +21,11 @@ object FreshNameCreator { * that the returned name has never been returned by a previous * call to this function (provided the prefix does not end in a digit). */ - def newName(prefix: String): String = { - val safePrefix = prefix.replaceAll("""[<>]""", """\$""") - counters(safePrefix) += 1 - val counter = counters(safePrefix) - if (prefix.isEmpty) "$" + counter + "$" else safePrefix + counter + def newName(prefix: TermName, unique: UniqueNameKind): TermName = { + val key = str.sanitize(prefix.toString + unique.separator) + counters(key) += 1 + val counter = counters(key) + prefix.derived(unique.NumberedInfo(counter)) } } } diff --git a/compiler/src/dotty/tools/dotc/util/NameTransformer.scala b/compiler/src/dotty/tools/dotc/util/NameTransformer.scala index 330d513fe..52f8e6ec0 100644 --- a/compiler/src/dotty/tools/dotc/util/NameTransformer.scala +++ b/compiler/src/dotty/tools/dotc/util/NameTransformer.scala @@ -60,7 +60,7 @@ object NameTransformer { * @param name the string to encode * @return the string with all recognized opchars replaced with their encoding */ - def encode[N <: Name](name: N): N = { + def encode(name: SimpleTermName): SimpleTermName = { var buf: StringBuilder = null val len = name.length var i = 0 @@ -87,8 +87,7 @@ object NameTransformer { i += 1 } if (buf eq null) name - else if (name.isTermName) buf.toString.toTermName.asInstanceOf[N] - else buf.toString.toTypeName.asInstanceOf[N] + else termName(buf.toString) } /** Replace `\$opname` by corresponding operator symbol. |