diff options
author | Martin Odersky <odersky@gmail.com> | 2017-03-28 22:25:09 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2017-04-11 09:33:11 +0200 |
commit | ca5652cc5a74f00277ce942a001fa6e931ee3728 (patch) | |
tree | 9ef6e2b341bc10678bbe1f06d4c15fb28093da07 /compiler/src/dotty/tools/dotc/util | |
parent | 1e49ddad97c4e8207913857511ae62467f8cd3ce (diff) | |
download | dotty-ca5652cc5a74f00277ce942a001fa6e931ee3728.tar.gz dotty-ca5652cc5a74f00277ce942a001fa6e931ee3728.tar.bz2 dotty-ca5652cc5a74f00277ce942a001fa6e931ee3728.zip |
Make freshName semantic
Diffstat (limited to 'compiler/src/dotty/tools/dotc/util')
-rw-r--r-- | compiler/src/dotty/tools/dotc/util/FreshNameCreator.scala | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/compiler/src/dotty/tools/dotc/util/FreshNameCreator.scala b/compiler/src/dotty/tools/dotc/util/FreshNameCreator.scala index 8892a570e..529e30f05 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.NameExtractors.UniqueNameExtractor +import core.StdNames.str -trait FreshNameCreator { - def newName(prefix: String = ""): String +abstract class FreshNameCreator { + def newName(prefix: TermName, unique: UniqueNameExtractor): 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: UniqueNameExtractor): TermName = { + val key = str.sanitize(prefix.toString + unique.separator) + counters(key) += 1 + val counter = counters(key) + prefix.derived(unique.NumberedInfo(counter)) } } } |