diff options
Diffstat (limited to 'src')
5 files changed, 38 insertions, 56 deletions
diff --git a/src/compiler/scala/tools/nsc/CompilationUnits.scala b/src/compiler/scala/tools/nsc/CompilationUnits.scala index 1de5c1f626..59ac123fe6 100644 --- a/src/compiler/scala/tools/nsc/CompilationUnits.scala +++ b/src/compiler/scala/tools/nsc/CompilationUnits.scala @@ -5,8 +5,7 @@ package scala.tools.nsc -import util.FreshNameCreator -import scala.reflect.internal.util.{ SourceFile, NoSourceFile } +import scala.reflect.internal.util.{ SourceFile, NoSourceFile, FreshNameCreator } import scala.collection.mutable import scala.collection.mutable.{ LinkedHashSet, ListBuffer } import scala.tools.nsc.reporters.Reporter @@ -27,7 +26,7 @@ trait CompilationUnits { global: Global => class CompilationUnit(val source: SourceFile) extends CompilationUnitContextApi { self => /** the fresh name creator */ - val fresh: FreshNameCreator = new FreshNameCreator.Default + val fresh: FreshNameCreator = new FreshNameCreator def freshTermName(prefix: String): TermName = newTermName(fresh.newName(prefix)) def freshTypeName(prefix: String): TypeName = newTypeName(fresh.newName(prefix)) diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala index 032c0c34b3..6f5d9f289b 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala @@ -13,9 +13,8 @@ import scala.collection.{ mutable, immutable } import mutable.{ ListBuffer, StringBuilder } import scala.reflect.internal.{ ModifierFlags => Flags } import scala.reflect.internal.Chars.{ isScalaLetter } -import scala.reflect.internal.util.{ SourceFile, Position } +import scala.reflect.internal.util.{ SourceFile, Position, FreshNameCreator } import Tokens._ -import util.FreshNameCreator /** Historical note: JavaParsers started life as a direct copy of Parsers * but at a time when that Parsers had been replaced by a different one. @@ -164,7 +163,7 @@ self => val in = newScanner() in.init() - private val globalFresh = new FreshNameCreator.Default + private val globalFresh = new FreshNameCreator def unit = global.currentUnit def freshName(prefix: String): Name = freshTermName(prefix) diff --git a/src/compiler/scala/tools/nsc/util/FreshNameCreator.scala b/src/compiler/scala/tools/nsc/util/FreshNameCreator.scala deleted file mode 100644 index e877c990f0..0000000000 --- a/src/compiler/scala/tools/nsc/util/FreshNameCreator.scala +++ /dev/null @@ -1,40 +0,0 @@ -/* NSC -- new Scala compiler - * Copyright 2005-2013 LAMP/EPFL - * @author Martin Odersky - */ - -package scala.tools.nsc -package util - -import scala.collection.mutable - -trait FreshNameCreator { - /** Do not call before after type checking ends. - * PP: I think that directive needs to lose a word somewhere. - */ - def newName(): String - def newName(prefix: String): String -} - -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 + "$" - } - } -} diff --git a/src/reflect/scala/reflect/internal/BuildUtils.scala b/src/reflect/scala/reflect/internal/BuildUtils.scala index b46408624c..39dfe60ecf 100644 --- a/src/reflect/scala/reflect/internal/BuildUtils.scala +++ b/src/reflect/scala/reflect/internal/BuildUtils.scala @@ -131,18 +131,11 @@ trait BuildUtils { self: SymbolTable => def RefTree(qual: Tree, sym: Symbol) = self.RefTree(qual, sym.name) setSymbol sym - def withFreshTermName[T](prefix: String)(f: TermName => T): T = f(TermName(freshName(prefix))) + def withFreshTermName[T](prefix: String)(f: TermName => T): T = f(TermName(freshNameCreator.newName(prefix))) - def withFreshTypeName[T](prefix: String)(f: TypeName => T): T = f(TypeName(freshName(prefix))) + def withFreshTypeName[T](prefix: String)(f: TypeName => T): T = f(TypeName(freshNameCreator.newName(prefix))) - object freshName { - private val counters = collection.mutable.HashMap[String, Int]() withDefaultValue 0 - def apply(prefix: String): String = { - val safePrefix = prefix.replaceAll("""[<>]""", """\$""") - counters(safePrefix) += 1 - safePrefix + counters(safePrefix) - } - } + private val freshNameCreator = new util.FreshNameCreator object FlagsRepr extends FlagsReprExtractor { def apply(bits: Long): FlagSet = bits diff --git a/src/reflect/scala/reflect/internal/util/FreshNameCreator.scala b/src/reflect/scala/reflect/internal/util/FreshNameCreator.scala new file mode 100644 index 0000000000..8fe4a715f3 --- /dev/null +++ b/src/reflect/scala/reflect/internal/util/FreshNameCreator.scala @@ -0,0 +1,31 @@ +/* NSC -- new Scala compiler + * Copyright 2005-2013 LAMP/EPFL + * @author Martin Odersky + */ + +package scala.reflect.internal +package util + +import scala.collection.mutable + +class 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 + "$" + } +} |