aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/util/FreshNameCreator.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2013-04-17 09:48:22 +0200
committerMartin Odersky <odersky@gmail.com>2013-04-17 10:16:22 +0200
commitca8dc7ada663e44aafe470944dd17256dbde151c (patch)
treed15939e204042e358e0c83064250f1f18c1c4f25 /src/dotty/tools/dotc/util/FreshNameCreator.scala
parente32fedb6844eab11a27e365a570b2033a0f6f78d (diff)
downloaddotty-ca8dc7ada663e44aafe470944dd17256dbde151c.tar.gz
dotty-ca8dc7ada663e44aafe470944dd17256dbde151c.tar.bz2
dotty-ca8dc7ada663e44aafe470944dd17256dbde151c.zip
Scanners added.
Moving Positions, Chars to new packages. Added Source positions. Added untyped trees module. Factored out behavior between typed and untyped trees.
Diffstat (limited to 'src/dotty/tools/dotc/util/FreshNameCreator.scala')
-rw-r--r--src/dotty/tools/dotc/util/FreshNameCreator.scala38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/dotty/tools/dotc/util/FreshNameCreator.scala b/src/dotty/tools/dotc/util/FreshNameCreator.scala
new file mode 100644
index 000000000..d0c007d94
--- /dev/null
+++ b/src/dotty/tools/dotc/util/FreshNameCreator.scala
@@ -0,0 +1,38 @@
+package dotty.tools
+package dotc
+package util
+
+import scala.collection.mutable
+
+trait FreshNameCreator {
+ def newName(): String
+ def newName(prefix: String): String
+
+ @deprecated("use newName(prefix)", "2.9.0")
+ def newName(pos: scala.reflect.internal.util.Position, prefix: String): String = newName(prefix)
+ @deprecated("use newName()", "2.9.0")
+ def newName(pos: scala.reflect.internal.util.Position): String = newName()
+}
+
+object FreshNameCreator {
+ class Default extends FreshNameCreator {
+ protected var counter = 0
+ protected val counters = mutable.HashMap[String, Int]() withDefaultValue 0
+
+ /**
+ * Create a fresh name with the given prefix. It is guaranteed
+ * 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
+
+ safePrefix + counters(safePrefix)
+ }
+ def newName(): String = {
+ counter += 1
+ "$" + counter + "$"
+ }
+ }
+}